fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. struct Node{
  4. int val;
  5. Node*next;
  6. };
  7. Node*InsertAtEnd(Node*root,int x)
  8. {
  9. Node*newnode;
  10. newnode->next=NULL;
  11. newnode->val=x;
  12. if(root==NULL)
  13. {
  14. root=newnode;
  15. return root;
  16. }
  17. Node*currnode;
  18. currnode=root;
  19. while(currnode->next!=NULL)
  20. {
  21. currnode=currnode->next;
  22. }
  23. currnode->next=newnode;
  24. return root;
  25. }
  26. void Print(Node*root)
  27. {
  28. Node*currnode;
  29. currnode=root;
  30. while(currnode!=NULL)
  31. {
  32. cout<<currnode->val<<" ";
  33. currnode=currnode->next;
  34. }
  35. cout<<endl;
  36. }
  37. int main()
  38. {
  39. Node*root=NULL;
  40. root=InsertAtEnd(root,7);
  41. root=InsertAtEnd(root,5);
  42. Print(root);
  43. }
  44.  
  45.  
Success #stdin #stdout 0s 5272KB
stdin
Standard input is empty
stdout