fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3. struct node{
  4. int data;
  5. node *next;
  6. };
  7.  
  8. int main() {
  9. int n;
  10. cin >> n;
  11. node *head,*p;
  12. head = p = new node;
  13. cin >> p->data;
  14. n--;
  15. while(n)
  16. {
  17. node *q = new node;
  18. cin >> q->data;
  19. p->next = q;
  20. p = p->next;
  21. n--;
  22. }
  23. p->next = NULL;
  24.  
  25. p = head;
  26. while(p!=NULL)
  27. {
  28. cout << p->data << " ";
  29. p = p->next;
  30. }
  31. return 0;
  32. }
Success #stdin #stdout 0.01s 5472KB
stdin
5
1 2 3 4 5
stdout
1 2 3 4 5