从链表排序元素 [英] sorting element from linked list

查看:192
本文介绍了从链表排序元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

void sortlist()
{
    struct node *a;
    struct node *temp=head;

    struct node *temp1=head->next;

    while(temp!=NULL)
    {
        while(temp1->next!=NULL)
        {
            if(temp->data > temp1->data)
            {
                a->data=temp->data;
                temp->data=temp1->data;
                temp1->data=a->data;
            }
            else
            {
                temp1=temp1->next;
            }
        }
        temp=temp->next;
    }
}

//我是新来的数据structures.i我在这里遇到了一些问题,而试图理清链接list.list的元素没有得到sorted.any帮助是极大的AP preciated。

//I am new to data structures.i am encountering some problem here while trying to sort elements of linked list.list does not get sorted.any help is greatly appreciated.

推荐答案

//最后我找到了答案,我自己的问题,这是解决方案,感谢您的帮助哥们

//at last i found answer to my own problem and this is the solution,thanks for your help buddies

void sortlist()
{
    struct node *temp=head;
    int s;
    struct node *temp1=temp->next;

    while(temp!=NULL)
    {
        temp1=temp->next;                       
        while(temp1!=NULL)
        {
            if(temp->data > temp1->data)
            {
                s=temp->data;
                temp->data=temp1->data;
                temp1->data=s;
            }
            temp1=temp1->next;
        }
        temp=temp->next;
    }
}

这篇关于从链表排序元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆