阅读以下说明和c++代码,将应填入(n)处的字句写在对应栏内。【说明】本程序将两个从小到大的有序链表合成一个新的从小到大的有序链表。链表的每一项由类 Node描述,而链表由List描述,类List的成员函数有以下几个:creatList(): 创建从小到大的有序链表。multiplyList(List L1, Llst L2): 将链表L1和链表L2合并。print(): 打印链表。【C++代码】include <iostream>using namespace std;class List;class Node{friend class List;public:Node(int data){(1);}private:int data;Node *next;};class List{public:List(){list=NULL;}void multiplyList(List L1, List L2);void creatList();void print();private:Node *list;};void List::creatList(){Node *p, *u, *pre;int dara;list=NULL;wbile(1){cout<<"输入链表的一项: (小于零,结束链表) "<<endl;cin>>data;if(dara<0)break;//小于零,结束输入p=list;while(p !=NULL dara>p->data){//查找插入点pre=p;p=p->next;}u=(2);if(p==list)list=u;else pre->next=u;(3);}}void List::multiplyList(List L1, List L2){Node *pL1, *pL2, *pL, *u;list = NULL;pL1 = L1.list;pL2 = L2.11st;while(pL1 != NULL pL2 != NULL){if(pL1->data < pL2->data){u = new Node(pL1->data);pL1 = pL1->next;}else{u = new Node(pL2->data);pL2 = pL2->next;}if(list == NULL){list =(4);}else{pL->next=u;pL=u;}}pL1 = (pL1 != NULL)? pL1:pL2;while(pL1 != NULL){u=(5);pL1 = pL1->next;if(list == NULL){list=pL=u;}else{pL->next=u;pL=u;}}}void List::print(){Node *p;p = list;while(p !=NULL){cout<<p->data<<"\t";p=p->next;&
阅读以下说明和c++代码,将应填入(n)处的字句写在对应栏内。
【说明】
本程序将两个从小到大的有序链表合成一个新的从小到大的有序链表。链表的每一项由类 Node描述,而链表由List描述,类List的成员函数有以下几个:
creatList(): 创建从小到大的有序链表。
multiplyList(List L1, Llst L2): 将链表L1和链表L2合并。
print(): 打印链表。
【C++代码】
include <iostream>
using namespace std;
class List;
class Node{
friend class List;
public:
Node(int data){
(1);
}
private:
int data;
Node *next;
};
class List{
public:
List(){list=NULL;}
void multiplyList(List L1, List L2);
void creatList();
void print();
private:
Node *list;
};
void List::creatList()
{
Node *p, *u, *pre;
int dara;
list=NULL;
wbile(1){
cout<<"输入链表的一项: (小于零,结束链表) "<<endl;
cin>>data;
if(dara<0)break;//小于零,结束输入
p=list;
while(p !=NULL && dara>p->data){//查找插入点
pre=p;
p=p->next;
}
u=(2);
if(p==list)list=u;
else pre->next=u;
(3);
}
}
void List::multiplyList(List L1, List L2)
{
Node *pL1, *pL2, *pL, *u;
list = NULL;
pL1 = L1.list;
pL2 = L2.11st;
while(pL1 != NULL && pL2 != NULL){
if(pL1->data < pL2->data){
u = new Node(pL1->data);
pL1 = pL1->next;
}else{
u = new Node(pL2->data);
pL2 = pL2->next;
}
if(list == NULL){
list =(4);
}else{
pL->next=u;
pL=u;
}
}
pL1 = (pL1 != NULL)? pL1:pL2;
while(pL1 != NULL){
u=(5);
pL1 = pL1->next;
if(list == NULL){
list=pL=u;
}else{
pL->next=u;
pL=u;
}
}
}
void List::print()
{
Node *p;
p = list;
while(p !=NULL){
cout<<p->data<<"\t";
p=p->next;
&