如何用C语言创建一个顺序存储的线性表并初始化

2024-12-31 23:14:21
推荐回答(1个)
回答1:

//---------------------------------------------------
//可创建任意长的链表
//---------------------------------------------------
#include

void main()
{
struct list
{
int name;
list *PN;
};
list *head;
list *ps;
list *pend;
ps=new list;
cout<<"输入0表示结束输入";
cin>>ps->name;
head=NULL;
pend=ps;

while(ps->name!=0)
{
if(head==NULL)
head=ps;
else
pend->PN=ps;
pend=ps;
ps=new list;
cin>>ps->name;
}
pend->PN=NULL;
delete ps;

while(head)
{
cout<name< head=head->PN;
}
}