void MergeList_L(LinkList - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

void MergeList_L(LinkList

Description:

Title: PowerPoint Presentation Last modified by: zzt Created Date: 1/1/1601 12:00:00 AM Document presentation format: Other titles – PowerPoint PPT presentation

Number of Views:47
Avg rating:3.0/5.0
Slides: 18
Provided by: educ5228
Category:

less

Transcript and Presenter's Notes

Title: void MergeList_L(LinkList


1
7?????????
  • ???,????????????????,?????????????,???????????,??
    ???????????????????????????

2
  • 1???????
  • void MergeList_L(LinkList LA,LinkList
    LB,LinkList LC)
  • //??????????,????????
  • LinkList pa,pb,pc
  • LCpcnew LNode
  • pc-gtnext0
  • paLA-gtnext
  • pbLB-gtnext
  • delete LA
  • delete LB

3
  • while(pa!0 pb!0)
  • if(pa-gtdataltpb-gtdata)
  • LApa-gtnext
  • pc-gtnextpa
  • paLA
  • pcpc-gtnext
  • else
  • LBpb-gtnext
  • pc-gtnextpb
  • pbLB
  • pcpc-gtnext
  • if(pa!0)
  • pc-gtnextpa

4
  • int main(int argc, char argv)
  • LinkList L1,L2,L3
  • InitList_L(L1)
  • InitList_L(L2)
  • ListInsert_L(L1,1,1)
  • ListInsert_L(L1,2,3)
  • ListInsert_L(L1,3,5)
  • ListInsert_L(L1,4,7)
  • ListInsert_L(L2,1,2)
  • ListInsert_L(L2,2,4)
  • ListInsert_L(L2,3,6)
  • ListInsert_L(L2,4,8)
  • print(L1)
  • print(L2)
  • MergeList_L(L1,L2,L3)
  • print(L3)
  • return 0

5
???
  • ?????
  • ????????????,?????????........( )

6
  • ???????
  • 1????????????,?9999??,9999????????????????????

7
  • ?????????????????????
  • includeltiostreamgt
  • using namespace std
  • struct node
  • int data
  • node next
  • ///
  • void print(node head)
  • node phead-gtnext
  • while(p)
  • coutltltp-gtdataltlt" "
  • pp-gtnext
  • coutltltendl

8
  • int main(int argc, char argv)
  • node headnew node//???
  • head-gtnext0
  • node tailhead//tail??????????
  • while(1)
  • int temp
  • cingtgttemp//????
  • if(temp9999)break
  • node pnew node//????
  • p-gtdatatemp
  • p-gtnext0
  • tail-gtnextp//??????
  • tailp//tail??
  • print(head)
  • return 0

9
  • 2????????????,?9999??,9999?????????????????????
  • ?????????????????????
  • includeltiostreamgt
  • using namespace std
  • struct node
  • int data
  • node next

10
  • int main(int argc, char argv)
  • node headnew node//???
  • head-gtnext0
  • while(1)
  • int temp
  • cingtgttemp//????
  • if(temp9999)break
  • node pnew node//????
  • p-gtdatatemp
  • p-gtnexthead-gtnext//??????
  • head-gtnextp
  • return 0

11
  • 3???????????????list??,?????,??p??????????????????
    ?(?p?????????????)?
  • ????
  • //????list,??p???pre
  • prelist
  • while(pre-gtnext!p)
  • prepre-gtnext
  • //?p???????q,q???????r
  • qp-gtnext rq-gtnext
  • //????p?q???
  • pre-gtnextq
  • q-gtnextp
  • p-gtnextr

12
  • 4??????????????(??)???,???????????
  •   ? ???????,??????
  •   ? ???????,???????????????
  •   ? ???????,???????????
  • ????
  • includeltiostreamgt
  • using namespace std
  • struct node
  • int data
  • node next
  • ///
  • void print(node head)
  • node phead-gtnext
  • while(p)

13
  • int main(int argc, char argv)
  • node headnew node//???
  • head-gtnext0
  • while(1)
  • int temp
  • cingtgttemp//????
  • if(temp9999)break
  • node pnew node//????
  • p-gtdatatemp
  • p-gtnexthead-gtnext//??????
  • head-gtnextp
  • print(head)

14
  • int min//?????
  • node q//?????????
  • node p
  • phead-gtnext
  • qp
  • minq-gtdata
  • pp-gtnext
  • while(p)//?????
  • if(p-gtdataltmin)
  • minp-gtdata
  • qp
  • pp-gtnext
  • coutltlt"min"ltltminltltendl

15
  • if(min21)//???????
  • pq-gtnext
  • q-gtdatap-gtdata
  • p-gtdatamin
  • print(head)
  • if(min20)//???????
  • pq-gtnext
  • q-gtnextp-gtnext
  • delete p
  • print(head)
  • return 0

16
  • 5????????????head,??????????????key?,?????,
    ?????????key????????????(?????????????????)
  • ??????????????
  • struct node
  • int data
  • node next
  • ????????????????
  • ?????????????

17
  • void sort(node head)
  • node phead-gtnext
  • while(p)
  • node qp-gtnext
  • while(q)
  • if(q-gtdataltp-gtdata)//??????????
  • head-gtdatap-gtdata
  • p-gtdataq-gtdata
  • q-gtdatahead-gtdata
  • qq-gtnext
  • pp-gtnext
Write a Comment
User Comments (0)
About PowerShow.com