一个链表的模拟操作程序
源代码在线查看: 链表操作 .txt
#include"iostream.h"
#include"process.h"
//-----------------------------------------------------------
template
struct lian
{
lian * next;
t zhi;
lian()
{
next=NULL;
zhi=0;
}
//-----------------------------------------------------------
friend ostream& operator {
for (;a!=NULL;)
{
cout a=a->next ;
}
return cout;
}
//-------------------------------------------------------------
friend istream& operator >> (istream& cin,lian *a)
{
cin>>a->zhi;
return cin;
}
//----------------------------------------------------------------
lian * creat (lian * a)
{
cout int length;
cin>>length;
lian * top=a;
for (int i=1;i {
cout
lian * jiedian;
jiedian=new lian;
cin>>jiedian;
top->next=jiedian;
top=jiedian;
}
return a;
}
//----------------------------------------------------------
lian * lianjie(lian *a,lian * b)
{
lian *wei=a;
for(;wei->next!=NULL;)
{
wei=wei->next;
}
wei->next=b;
return a;
}
};
main()
{
for (int i=1;i;)
{
cout cout cout cout
int choice;
cin>>choice;
//--------------------------------------------------------
switch (choice)
{
case 1:
cout lian *a;
a=new lian;
a->creat (a);
cout lian *b;
b=new lian;
b->creat(b);
break;
//--------------------------------------------------------
case 2:
cout a->lianjie(a,b);
break;
case 3:
cout cout break;
//---------------------------------------------------------
case 4:
exit(1);
break;
}
}//for语句的结尾-------------------------------------
}