fork download
  1. #include <iostream>
  2. using namespace std;
  3. struct node{
  4. int data;
  5. node* next;
  6. };
  7. node *head=new node;
  8.  
  9. int main()
  10. {head->next=NULL;
  11. head->data=0;
  12. node *ptr=head;
  13.  
  14. int m;
  15. cin>>m;
  16. int j;
  17. cin>>j;
  18. head->data=j;
  19. j=0;int h;
  20. while(j<m-1)
  21. {
  22. cin>>h;
  23. node* n1= new node;
  24. ptr->next=n1;
  25. n1->data=h;
  26. n1->next=NULL;
  27. ptr=n1;
  28. }
  29. ptr=head;
  30. while(ptr!=NULL)
  31. {
  32. cout<<ptr->data<<"\t";
  33. ptr=ptr->next;
  34. }
  35. return 0;
  36. }
Running #stdin #stdout 0s 0KB
stdin
6
1 2 3 4 5 6
stdout