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