#include<iostream>
using namespace std;
struct node
{
int data;
node * next;
};
int main()
{
int i,m,n;
cin>>n;
node *head=new node();
head->next=NULL;
node *tail;
tail=head;
for(i=0;i<n;i++)
{
cin>>m;
node *p=new node();//建立一个新的结构体空间
tail->next=p;//不想让tail->next指向null
p->data=m;
p->next=NULL;
tail=tail->next;//tail指向p
}
node *t=head;
while(t->next!=NULL)
{
cout<<t->next->data<<endl;
t=t->next;
}
return 0;
}
链表尾插
最新推荐文章于 2023-08-02 22:18:51 发布