fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. struct node{
  6. int data;
  7. struct node* next;
  8. };
  9.  
  10.  
  11. int main() {
  12. // your code goes here
  13.  
  14. struct node* head;
  15. struct node* second;
  16. struct node* third;
  17. head=(struct node*)malloc(sizeof(struct node));
  18. second=(struct node*)malloc(sizeof(struct node));
  19. third=(struct node*)malloc(sizeof(struct node));
  20.  
  21. head->data=5;
  22. head->next=second;
  23. second->data=7;
  24. second->next=third;
  25. third->data=9;
  26. third->next=NULL;
  27.  
  28. struct node* tmp=head;
  29. while(tmp!=NULL){
  30. cout<<tmp->data<<endl;
  31. tmp=tmp->next;
  32. }
  33. return 0;
  34. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
5
7
9