给定单链表的结点结构 typedef struct node *link; struct node{int item,link next;); 将两个升序单链表归并为一个升序单链表。

admin2012-06-21  34

问题 给定单链表的结点结构
    typedef struct node *link;
    struct node{int item,link next;);
  将两个升序单链表归并为一个升序单链表。

选项

答案算法描述如下: link merge(link t1,link t2) { link x,t=malloc(sizeof*t); while(t1!=NULL&&t21=NULL) if(t1->item<t2->item){ t->next=t1;t=t->next;t1=t1->next; }else{ t->next=t2;t=t->next;t2=t2->next; } if(t1!=NULL)t->next=t1; if(t2!=NULL)t->next=t2; x=t;t=t->next;free(x); return t; }

解析
转载请注明原文地址:https://kaotiyun.com/show/s8xi777K
0

随机试题
最新回复(0)