(01)两个线性表的归并及其应用

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

第二章线性表(续)一、用单链表存储结构实现两个线性表的归并二、一元多项式的表示及相加(简介)一、两个线性表的归并引例:La=(3,5,8,11)Lb=(2,6,8,9,11,15,20)则:求La与Lb的归并,得结果线性表Lc如下:Lc=(2,3,5,6,8,8,9,11,11,15,20)单链表的物理实现过程:La35811^Lb26891115^20一、两个线性表的归并引例:La=(3,5,8,11)Lb=(2,6,8,9,11,15,20)则:求La与Lb的归并,得结果线性表Lc如下:Lc=(2,3,5,6,8,8,9,11,11,15,20)单链表的物理实现过程:La35811^Lb26891115^20Lcpapbpa=La-next;pb=Lb-next;Lc=pc=La;pc一、两个线性表的归并引例:La=(3,5,8,11)Lb=(2,6,8,9,11,15,20)则:求La与Lb的归并,得结果线性表Lc如下:Lc=(2,3,5,6,8,8,9,11,11,15,20)单链表的物理实现过程:La35811^Lb26891115^20Lcpapbpa=La-next;pb=Lb-next;Lc=pc=La;pc一、两个线性表的归并引例:La=(3,5,8,11)Lb=(2,6,8,9,11,15,20)则:求La与Lb的归并,得结果线性表Lc如下:Lc=(2,3,5,6,8,8,9,11,11,15,20)单链表的物理实现过程:La35811^Lb26891115^20Lcpapbpcwhile(pa&&pb){if(pa-data=pb-data){pc-next=pa;pc=pa;pa=pa-next;}else{pc-next=pb;pc=pb;pb=pb-next;}}一、两个线性表的归并引例:La=(3,5,8,11)Lb=(2,6,8,9,11,15,20)则:求La与Lb的归并,得结果线性表Lc如下:Lc=(2,3,5,6,8,8,9,11,11,15,20)单链表的物理实现过程:La35811^Lb26891115^20Lcpapbpcwhile(pa&&pb){if(pa-data=pb-data){pc-next=pa;pc=pa;pa=pa-next;}else{pc-next=pb;pc=pb;pb=pb-next;}}一、两个线性表的归并引例:La=(3,5,8,11)Lb=(2,6,8,9,11,15,20)则:求La与Lb的归并,得结果线性表Lc如下:Lc=(2,3,5,6,8,8,9,11,11,15,20)单链表的物理实现过程:La35811^Lb26891115^20Lcpapbpcwhile(pa&&pb){if(pa-data=pb-data){pc-next=pa;pc=pa;pa=pa-next;}else{pc-next=pb;pc=pb;pb=pb-next;}}一、两个线性表的归并引例:La=(3,5,8,11)Lb=(2,6,8,9,11,15,20)则:求La与Lb的归并,得结果线性表Lc如下:Lc=(2,3,5,6,8,8,9,11,11,15,20)单链表的物理实现过程:La35811^Lb26891115^20Lcpapbpcwhile(pa&&pb){if(pa-data=pb-data){pc-next=pa;pc=pa;pa=pa-next;}else{pc-next=pb;pc=pb;pb=pb-next;}}一、两个线性表的归并引例:La=(3,5,8,11)Lb=(2,6,8,9,11,15,20)则:求La与Lb的归并,得结果线性表Lc如下:Lc=(2,3,5,6,8,8,9,11,11,15,20)单链表的物理实现过程:La35811^Lb26891115^20Lcpapbpcwhile(pa&&pb){if(pa-data=pb-data){pc-next=pa;pc=pa;pa=pa-next;}else{pc-next=pb;pc=pb;pb=pb-next;}}一、两个线性表的归并引例:La=(3,5,8,11)Lb=(2,6,8,9,11,15,20)则:求La与Lb的归并,得结果线性表Lc如下:Lc=(2,3,5,6,8,8,9,11,11,15,20)单链表的物理实现过程:La35811^Lb26891115^20Lcpapbpcwhile(pa&&pb){if(pa-data=pb-data){pc-next=pa;pc=pa;pa=pa-next;}else{pc-next=pb;pc=pb;pb=pb-next;}}一、两个线性表的归并引例:La=(3,5,8,11)Lb=(2,6,8,9,11,15,20)则:求La与Lb的归并,得结果线性表Lc如下:Lc=(2,3,5,6,8,8,9,11,11,15,20)单链表的物理实现过程:La35811^Lb26891115^20Lcpapbpcwhile(pa&&pb){if(pa-data=pb-data){pc-next=pa;pc=pa;pa=pa-next;}else{pc-next=pb;pc=pb;pb=pb-next;}}一、两个线性表的归并引例:La=(3,5,8,11)Lb=(2,6,8,9,11,15,20)则:求La与Lb的归并,得结果线性表Lc如下:Lc=(2,3,5,6,8,8,9,11,11,15,20)单链表的物理实现过程:La35811^Lb26891115^20Lcpapbpcwhile(pa&&pb){if(pa-data=pb-data){pc-next=pa;pc=pa;pa=pa-next;}else{pc-next=pb;pc=pb;pb=pb-next;}}一、两个线性表的归并引例:La=(3,5,8,11)Lb=(2,6,8,9,11,15,20)则:求La与Lb的归并,得结果线性表Lc如下:Lc=(2,3,5,6,8,8,9,11,11,15,20)单链表的物理实现过程:La35811^Lb26891115^20Lcpapbpcwhile(pa&&pb){if(pa-data=pb-data){pc-next=pa;pc=pa;pa=pa-next;}else{pc-next=pb;pc=pb;pb=pb-next;}}一、两个线性表的归并引例:La=(3,5,8,11)Lb=(2,6,8,9,11,15,20)则:求La与Lb的归并,得结果线性表Lc如下:Lc=(2,3,5,6,8,8,9,11,11,15,20)单链表的物理实现过程:La35811^Lb26891115^20Lcpapbpcwhile(pa&&pb){if(pa-data=pb-data){pc-next=pa;pc=pa;pa=pa-next;}else{pc-next=pb;pc=pb;pb=pb-next;}}一、两个线性表的归并引例:La=(3,5,8,11)Lb=(2,6,8,9,11,15,20)则:求La与Lb的归并,得结果线性表Lc如下:Lc=(2,3,5,6,8,8,9,11,11,15,20)单链表的物理实现过程:La35811^Lb26891115^20Lcpapbpcwhile(pa&&pb){if(pa-data=pb-data){pc-next=pa;pc=pa;pa=pa-next;}else{pc-next=pb;pc=pb;pb=pb-next;}}一、两个线性表的归并引例:La=(3,5,8,11)Lb=(2,6,8,9,11,15,20)则:求La与Lb的归并,得结果线性表Lc如下:Lc=(2,3,5,6,8,8,9,11,11,15,20)单链表的物理实现过程:La35811^Lb26891115^20Lcpapbpcwhile(pa&&pb){if(pa-data=pb-data){pc-next=pa;pc=pa;pa=pa-next;}else{pc-next=pb;pc=pb;pb=pb-next;}}一、两个线性表的归并引例:La=(3,5,8,11)Lb=(2,6,8,9,11,15,20)则:求La与Lb的归并,得结果线性表Lc如下:Lc=(2,3,5,6,8,8,9,11,11,15,20)单链表的物理实现过程:La35811^Lb26891115^20Lcpapbpcwhile(pa&&pb){if(pa-data=pb-data){pc-next=pa;pc=pa;pa=pa-next;}else{pc-next=pb;pc=pb;pb=pb-next;}}^一、两个线性表的归并引例:La=(3,5,8,11)Lb=(2,6,8,9,11,15,20)则:求La与Lb的归并,得结果线性表Lc如下:Lc=(2,3,5,6,8,8,9,11,11,15,20)单链表的物理实现过程:La35811^Lb26891115^20Lcpapbpcwhile(pa&&pb){if(pa-data=pb-data){pc-next=pa;pc=pa;pa=pa-next;}else{pc-next=pb;pc=pb;pb=pb-next;}}if(pb)pc-next=pb;elsepc-next=pa;^一、两个线性表的归并引例:La=(3,5,8,11)Lb=(2,6,8,9,11,15,20)则:求La与Lb的归并,得结果线性表Lc如下:Lc=(2,3,5,6,8,8,9,11,11,15,20)单链表的物理实现过程:La35811^Lb26891115^20Lcpapbpcwhile(pa&&pb){if(pa-data=pb-data){pc-next=pa;pc=pa;pa=pa-next;}else{pc-next=pb;pc=pb;pb=pb-next;}}if(pb)pc-next=pb;elsepc-next=pa;^free(Lb);一、两个线性表的归并引例:La=(3,5,8,11)Lb=(2,6,8,9,11,15,20)则:求La与Lb的归并,得结果线性表Lc如下:Lc=(2,3,5,6,8,8,9,11,11,15,20)单链表的物理实现过程:35811^26891115^20Lcwhile(pa&&pb){if(pa-data=pb-data){pc-next=pa;pc=pa;pa=pa-next;}else{pc-next=pb;pc=pb;pb=pb-next;}}if(pb)pc-next=pb;elsepc-next=pa;一、两个线性表的归并引例:La=(3,5,8,11)Lb=(2,6,8,9,11,15,20)则:求La与Lb的归并,得结果线性表Lc如下:Lc=(2,3,5,6,8,8,9,11,11,15,20)单链表的物理实现过程:35811^26891115^20Lcwhile(pa&&pb){if(pa-data=pb-data){pc-next=pa;pc=pa;pa=pa-next;}else{pc-next=pb;pc=pb;pb=pb-next;}}if(pb)pc-next=pb;elsepc-next=pa;一、两个线性表的归并归并算法:voidMergeList_L(LinkList&La,LinkList&Lb,LinkList&Lc){pa=La-next;pb=Lb-next;Lc=pc=La;while(pa&&pb){if(pa-data=pb-data){pc-next=pa;pc=pa;pa=pa-next;}else{pc-next=

1 / 25
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功