#define LOCAL
#include<cstdio>
#include<cstdlib>
#include<iostream>
using namespace std;
typedef int ElemType;
typedef struct Node
{
ElemType data;
struct Node *next;
}Node,*LinkList;
void DisplayList(LinkList L)
{
Node *p=L->next;
cout<<"display:"<<L->data<<endl;
while(p!=NULL)
{
cout<<p->data<<",";
p=p->next;
}
}
void InitList(LinkList *L)
{
(*L)=(LinkList)malloc(sizeof(Node));
(*L)->next=NULL;
}
void CreateHeadList(LinkList L)
{
Node *p;
ElemType a;
L->data=0;
while(cin>>a)
{
p=(Node *)malloc(sizeof(Node));
p->data=a;
p->next=L->next;
L->next=p;
}
}
void CreateHeadList1(LinkList L)
{
Node *p,*h;
h=L->next;
ElemType a;
L->data=0;
while(cin>>a)
{
p=(Node *)malloc(sizeof(Node));
p->data=a;
L->data++;
p->next=h;
h=p;
}
L->next=h;//注意此处一定要有,就是把h连接到L->next后
}
void CreateTailList(LinkList L)
{
Node *p,*r;
ElemType a;
r=L;
L->data=0;
while(cin>>a)
{
p=(Node *)malloc(sizeof(Node));
p->data=a;
p->next=NULL;
L->data++;
r->next=p;
r=p;
}
r->next=NULL;
}
void UseT(LinkList &L)
{
//Node *p=(*L).next;
Node *p=L->next;
cout<<endl<<"&L:"<<endl;
while(p!=NULL)
{
cout<<p->data<<",";
p=p->next;
}
cout<<endl;
}
int main()
{
#ifdef LOCAL
freopen("2.in","r",stdin);
freopen("2.out","w",stdout);
#endif
LinkList Head;
InitList(&Head);
//CreateHeadList1(Head);
CreateTailList(Head);
DisplayList(Head);
UseT(Head);//放进去Head 然后&把Head打包
return 0;
}
display:10
1,2,3,4,5,6,7,8,9,10,
&L:
1,2,3,4,5,6,7,8,9,10,