轩辕

运筹帷幄世界在我手中!

导航

单链表排序

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;

}

posted on 2013-02-23 12:01  峻华  阅读(87)  评论(0)    收藏  举报