用户:
SCS_user_EHQ0z2l6el查看:0 回复:0 评论:0 创建时间:2022-09-03T18:03:50
哈哈嗨
这次是模拟链表)
#include<iostream>
using namespace std;
struct Node{
int data;
Node *next;
};
Node *head,*p,*r;
int x;
void print(){
p=head->next;
while(p->next!=NULL){
cout<<p->data<<"->";
p=p->next;
}
cout<<p->data<<endl;
}
void makenode(){//构建链表
cin>>x;
head=new Node;
r=head;
while(x!=-1){
p=new Node;
p->data=x;
p->next=NULL;
r->next=p;
r=p;
cin>>x;
}
}
int main(){
makenode();
print();
return 0;
}