#include< iostream>//cin,cout函数使用
using namespace std;//避免重名,个人理解
typedef struct node{
int data;
struct node *next;
}node,*linklist; //这是节点的类型,数据+指针
linklist Create()//链表创建函数,用的是类型是指针,方法后插法,返回
{ //类型是指针,调用时 (接x)
linklist head,p,tail;
cout<<“请输入链表数据,以0结束!!!”<<endl;
head=p=tail=new node;//开辟一个结点,head,p,tail指向它
cin>>p->data;
while(p->data!=0)
{
tail->next=p;//尾巴后面有个指针p,这样做好连接的准备
tail=p;//尾巴往后移
p=new node;//p指向新开辟的结点
cin>>p->data;//输入数据
}
tail->next=NULL;
cout<<“链表创建完毕!!!”<<endl;
return head;//返回链表头指针
}
void Show(node *head)//链表输出函数,这个函数的意思是,给我一个
{ //指针,我把它从此针到尾巴输出,参数是个指针
node *p;
p=head;
while§
{
cout<data<<" ";
p=p->next;
}
cout<<endl;
cout<<“链表输出完毕!!!”<<endl;
}
int main()
{
node *head;
head=Create();//(接x)意思是我头指针指向这么个链表,此链表在上面已创建
Show(head);
return 0;
}