链表
2023-08-26 09:50:49
发布于:浙江
#include <bits/stdc++.h>
using namespace std;
struct node{
int data;//存储当前结点的值
node *next;//存储下一个结点的地址
};
int main(){
node *head,*r;//定义头结点和尾结点
head = new node;
head -> next =NULL;
r=head;
node *p;
int x;
while(cin>>x){
p=new node;
p->data=x;
p->next=NULL;
r->next=p;
r=p;
}
p=head;
while(p->next!=NULL){
cout<<p->next->data<<" ";
p=p->next;
}
return 0;
}
这里空空如也
有帮助,赞一个