冒泡法排序 单链表进行升序排序
将一个已经建立的单向链表进行升序排序程序如下:
程序代码: void sort(stu *head)
{ stu *ptr,*preptr,*endptr;
int t;
ptr=head->next;
while(ptr->next!=NULL)
ptr=ptr->next;
endptr=ptr;
ptr=head->next;
while(ptr!=endptr)
{ while(ptr->next!=NULL)
{ if(ptr->data>ptr->next->data)
{ t=ptr->data;
ptr->data=ptr->next->data;
ptr->next->data=t;
}
preptr=ptr; ptr=ptr->next;
}
endptr=preptr; ptr=head->next;
}
} 程序运行没有结果!!!不知道程序错在哪里,大家看一下









