#include
#include
#include
typedef struct node
{
int date;
struct node *next;
}slnode,*Linklist;
void creat_list(Linklist H)//创建链表,由于实参传值使L指向了一个空节点从而成为头节点指针
{
Linklist p, p1;
int n;
cout<
cin>>n;
H->date=n;
cout<
p1 = H;//使p1具有了空间
for(int i=0;i
{
p=(Linklist)malloc(sizeof(slnode));
p->next = NULL;
cin>>p->date;
H->next = p;
H=p;//L指向了最后节点的数据域
};
H=p1;//使尾指针指向了最后节点的数据域
}
void display_list(Linklist H)//输出链表
{
cout<
Linklist p;
p = H-> next;
for(int i=0;idate;i++)
{
cout<date;
cout << ' ';cout<
p = p -> next;
}
}
void main()
{
slnode a;//a是空结构变量
Linklist p;//p是指针
p = &a;//p指向了一个空节点
creat_list(p);//传的是结构变量的地址
display_list(p);
}