C++单链表的输出
2025-05-05 14:13:32
发布于:浙江
#include<bits/stdc++.h>
using namespace std;
struct node{
int data;
node *next;
};
int main(){
int n,x;
cin >> n;
node *head,*r,*p;
head=new node;
head->next=NULL;
r=head;
for(int i=1;i<=n;i++){
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;
}
这里空空如也
有帮助,赞一个