编程实现单链表的排序

来源:互联网 发布:mac系统怎么制作铃声 编辑:程序博客网 时间:2024/06/05 22:45
node *sort(node *head)
{
node *p, *p2, *p3;
int n;
int temp;
n = length(head);
if (head == NULL || head->next == NULL)
return head;
p = head;
for (int j = 1; j < n; ++j)
{
p = head;
for (int i = 0; i < n - j; ++i)
{
if (p->data>p->next->data)
{
temp = p->data;
p->data = p->next->data;
p->next->data = temp;
}
p = p->next;
}
}
return head;
}
0 0
原创粉丝点击