#include<iostream>
using namespace std;
struct node{
int data;
node*next;
};
node*create(int n){
node*head,*tail,*p;
head=tail=new node;
head->data=0;
//可用浪费一小段空间的方法节省时间。
while(n--){
p=new node;
cin>>p->data;
p->next=NULL;
tail->next=p;
tail=p;
}
return head;
}
int main() {
int n=3;
node*p;
p=create(3);
p=p->next;//跳过表头指针
while(p){
cout<<p->data<<" ";
p=p->next;
}
return 0;
}
C++尾插入链表_循环实现
最新推荐文章于 2024-04-19 21:49:00 发布