
陆表 【程序1】 愿目:创建一个歧表。 1程序分析: 2程序源代码 /产creat a list/ Minclude "stdib.h" #include "stdo.h" struct Ist int data; struct lst "next k typedef struct list node: typedef node *link: void main) link ptr,head; int num,i: ptr-(link)malloc(sizeof(nodell: ptrshead; printf["please input 5 numbers=n"): ori-0e✉4:i+) scanf("%d,&num): ptr->datamnum; ptr->next=(ink malloc(sizeof(node)]: f=4)P咳r>next=MU山 else ptrmptr->next: ptrehead;
链表 【程序 1】 题目:创建一个链表。 1.程序分析: 2.程序源代码: /*creat a list*/ #include "stdlib.h" #include "stdio.h" struct list { int data; struct list *next; }; typedef struct list node; typedef node *link; void main() { link ptr,head; int num,i; ptr=(link)malloc(sizeof(node)); ptr=head; printf("please input 5 numbers==>\n"); for(i=0;idata=num; ptr->next=(link)malloc(sizeof(node)); if(i==4) ptr->next=NULL; else ptr=ptr->next; } ptr=head;

while(ptrl-NULL] {printf("The value is =>%d小n',ptr->d内ta小 ptrmptr-next: 1 【程序2】 恶目:反向输出一个链表。 1程序分析: 2程序濛代码: reverse output a list'/ #include "stdib.h" nclude"stdo.h° structlst (int data; struct list "next; typedef structlist node; typedef node "link: void main( (link ptr,head,tall int num,ic tail-(linkmalloc(sizeof(node)l: taionext-=NU具L与 ptretail: printf["nplease input 5 dataVn"): for(i-0;ic4;i++) scant[%d",&numl: ptr-data-num:
while(ptr!=NULL) { printf("The value is ==>%d\n",ptr->data); ptr=ptr->next; } } 【程序 2】 题目:反向输出一个链表。 1.程序分析: 2.程序源代码: /*reverse output a list*/ #include "stdlib.h" #include "stdio.h" struct list { int data; struct list *next; }; typedef struct list node; typedef node *link; void main() { link ptr,head,tail; int num,i; tail=(link)malloc(sizeof(node)); tail->next=NULL; ptr=tail; printf("\nplease input 5 data==>\n"); for(i=0;idata=num;

head=(link)mallod(sizecnodel: head->next-日 ptrahead; pt-pt-et用 while(ptrl=NULL] {printf("The value is =%dn",ptr->datal: ptr=ptr->next; 业 【程序3】 题目,连接两个链表。 1程序分析: 2程序源代码: #include "stdib.h" #nclude "stdoh" struct Est (int data; struct lst"next; 上 typedef struct list node: typedef node "link: link delete_node(link pointer,link tmp) if (tmp==NUL山产delete first node/ return pointer-onext ekse if(tmp->next->next=-NULLdelete last node*/ tmp->next-NULL; else/delete the other node"/ tmp->next=tmp-onextonext;
head=(link)malloc(sizeof(node)); head->next=ptr; ptr=head; } ptr=ptr->next; while(ptr!=NULL) { printf("The value is ==>%d\n",ptr->data); ptr=ptr->next; }} 【程序 3】 题目:连接两个链表。 1.程序分析: 2.程序源代码: #include "stdlib.h" #include "stdio.h" struct list { int data; struct list *next; }; typedef struct list node; typedef node *link; link delete_node(link pointer,link tmp) {if (tmp==NULL) /*delete first node*/ return pointer->next; else { if(tmp->next->next==NULL)/*delete last node*/ tmp->next=NULL; else /*delete the other node*/ tmp->next=tmp->next->next;

return pointer; void selection_sort(link pointer,int num) link tmp.btmp: int i,min; for(i-0:i tmpmpointer: min-tmp-odata: btmp-NULL: whie(tmp->next) if(min>tmp->next->data] mn-tmp->ncxt-2c由ta b城mp-tmg } tmp=tmp-onext; / prnt4d:%d小n',mlng pointer=delete_nodelpointer,btmp: 1 link create_list(int array[l.int num) link tmp1,tmp2.pointer: inti; pointer=[link)malloc(sizeofnode]: pointer->datazarray0 tmpl=pointer: for(i1tmp2-[link]malloc(sizeof(node)): tmp2->next=NULL: tmp2->data=array]:
return pointer; } } void selection_sort(link pointer,int num) { link tmp,btmp; int i,min; for(i=0;i { tmp=pointer; min=tmp->data; btmp=NULL; while(tmp->next) { if(min>tmp->next->data) {min=tmp->next->data; btmp=tmp; } tmp=tmp->next; } printf("\40: %d\n",min); pointer=delete_node(pointer,btmp); } } link create_list(int array[],int num) { link tmp1,tmp2,pointer; int i; pointer=(link)malloc(sizeof(node)); pointer->data=array[0]; tmp1=pointer; for(i=1;i{ tmp2=(link)malloc(sizeof(node)); tmp2->next=NULL; tmp2->data=array[i];

tmpl->next-tmo2: tmpl=tmp1->next; return pointer: link concatenatellink pointer],link pointer2) {link tmp tmp=pointer1; while(tmp->next) tmp=tmp->next; tmp->next=pointer2; return pointer1: void main(void) {int arr10-312,89,11k link ptr: ptr=create_list(arr1,5): selection_sort/ptr.5
tmp1->next=tmp2; tmp1=tmp1->next; } return pointer; } link concatenate(link pointer1,link pointer2) { link tmp; tmp=pointer1; while(tmp->next) tmp=tmp->next; tmp->next=pointer2; return pointer1; } void main(void) { int arr1[]={3,12,8,9,11}; link ptr; ptr=create_list(arr1,5); selection_sort(ptr,5); }