1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| #include <iostream> #include <cstring> using namespace std; struct node { int data; struct node *next; };
int main () { std::ios::sync_with_stdio(false); struct node *head, *tail, *p; head = new node; head->next = NULL; tail = head; int N ; int tmpN; cin>>N; { tmpN = N; while(tmpN--) { p = new node; cin >> p->data ; p->next = head->next; head->next = p; } p = head->next; while(p->next!=NULL) { cout<<p->data<<' '; p=p->next; } cout<<p->data<<' ';
cout<<endl; }
return 0; }
|