?? 1.cpp
字號:
#include "LinkList.h"
void main()
{
LinkList A,B,C;
LNode *p,*q,*r,*pa,*pb,*pre,*pc;
ElemType m,n;
cout<<"請輸入鏈表A的長度:"<<endl;
cin>>m;
CreatList_L(A,m);
PrintList_L(A);
cout<<"請輸入鏈表B的長度:"<<endl;
cin>>n;
CreatList_L(B,n);
PrintList_L(B);
CreatList_L(C,0);
/*將A和B合并成非遞增鏈表
pa=A->next;pb=B->next;pre=NULL; //pa和pb分別指向A,B的當(dāng)前元素
while(pa||pb)
{
if(pa&&pb&&pa->data<pb->data)
{
pc=pa;q=pa->next;pa->next=pre;pa=q; //將A的元素插入新表
}
else
{
pc=pb;q=pb->next;pb->next=pre;pb=q;//將B的元素插入新表
}
if(pb==NULL){pc=pa;q=pa->next;pa->next=pre;pa=q;}
if(pa==NULL){pc=pb;q=pb->next;pb->next=pre;pb=q;}
//將B的元素插入新表
pre=pc;
}
C=A;A->next=pc; //構(gòu)造新表頭
*/
//將A和B合并成非遞減鏈表
p=A->next,q=B->next,r=C;
while(p!=NULL&&q!=NULL)
{
if(p->data<q->data)
{
r->next=p;p=p->next;
}//if
else
{
r->next=q;q=q->next;
}//else
r=r->next;
}//while
if(p==NULL) r->next=q;
if(q==NULL) r->next=p;
PrintList_L(C);
//將C按遞減排序
q=C;
for(int i=0;i<m+n-1;i++)
//while(q->next)
{
p=q->next;r=q;
while(p->next!=NULL)
{
if(p->data<p->next->data)
{
r->next=p->next;
r=r->next;
p->next=r->next;
r->next=p;
}//if
else
{
r=r->next;
p=p->next;
}//else
}//while
//q=q->next;
// }//while
}//for
PrintList_L(C);
}//main
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -