2011年计算机等级考试二级C语言辅导实例编程(17)

2014-10-28 19:30:06 · 作者: · 浏览: 153

  单链表冒牌排序


  今天做链表排序有个误区,就是以为交换的时候要连next节点也交换,还要固定head节点,想了很久也没做出来,但是后来看网上的提示,才知道只要交换节点内的数据就可以了,根本不用交换next节点


  01 #include


  02 #include


  03


  04 struct node


  05 {


  06 int data;


  07 struct node *next;


  08 };


  09


  10 struct node *create_list(int a[],int len)


  11 {


  12 struct node *phead;


  13 struct node *ptr;


  14 struct node *pre;


  15 phead=(struct node *)malloc(sizeof(struct node));


  16 int i=0;


  17 phead->data=a[i];


  18 phead->next=NULL;


  19 ptr=phead->next;


  20 pre=phead;


  21 for(i=1;i


  编辑特别推荐: