汤园是只猫 • 4个月前
using namespace std; typedef struct node {
int data;
node *next;
} *linklist;
void inital(linklist &l) {
l = new node;
l->next = NULL;
}
void create(linklist &l) {
node *r = l;
int x;
cin >> x;
while (x != -1) {
node *s = new node;
s->data = x;
s->next = l->next;
l->next = s;
cin >> x;
}
}
void printfl(linklist l) {
node *cur = l->next;
while (cur != NULL) {
cout << cur->data << " ";
cur = cur->next;
}
}
int main() {
linklist l;
inital(l);
create(l);
printfl(l);
return 0;
}
评论:
请先登录,才能进行评论