hello,world

c语言单链表,冒泡排序

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 @ 2013-09-17 15:53  study丶life  阅读(2879)  评论(0编辑  收藏  举报