C语言,合并增序减序链表

[复制链接]
查看11 | 回复0 | 2009-12-31 10:45:10 | 显示全部楼层 |阅读模式
#include#include#includetypedefintElemType;typedefstructLNODE{ElemTypeelem;structLNODE*next;}lnode,*linklist;voidInit(linklist*L){*L=(linklist)malloc(sizeof(lnode));(*L)->next=NULL;}voidListinsert(linklistL,inti,ElemTypee){intj=1;linklistp,s;p=L;while(jnext;j++;}s=(linklist)malloc(sizeof(lnode));s->next=p->next;p->next=s;s->elem=e;}voidUnion(linklistLa,linklistLb,linklistLc){linklistpa,pb,pc;pa=La->next;pb=Lb->next;pc=Lc;if(pa->elemnext->elem){while(pa&&pb){if(pa->elemelem){pc->next=pa;pc=pa;pa=pa->next;}else{pc->next=pb;pc=pb;pb=pb->next;}}pc->next=pa?pa:pb;}else{while(pa&&pb){if(pa->elem>pb->elem){pc->next=pa;pc=pa;pa=pa->next;}else{pc->next=pb;pc=pb;pb=pb->next;}}pc->next=pa?pa:pb;}}voidInputlist(linklistL,intmax){inti,e;for(i=1;inext){p=p->next;printf("%d\t",p->elem);j++;}}intmain(){linklistLa,Lb,Lc;Init(&La);Init(&Lb);Init(&Lc);printf("PleaseinputthedatesofLa:\n");inta,b;printf("Inputthesize:");scanf("%d",&a);printf("Inputtheelem:");Inputlist(La,a);printf("PleaseinputthedatesofLb:\n");printf("Inputthesize:");scanf("%d",&b);printf("Inputtheelem:");Inputlist(Lb,b);printf("\nThedatesofLaare:\n");Printlist(La);printf("\nThedatesofLbare:\n");Printlist(Lb);printf("\n");Union(La,Lb,Lc);printf("ThedatesofLcare:\n");Printlist(Lc);return0;}这是重新写的,我运行的没有问题,你看行不行
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行