Advertisement
q1sm4t

Untitled

Apr 11th, 2021
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. using namespace std;
  5.  
  6. struct n {
  7.     int x;
  8.     n * next;
  9. };
  10.  
  11. typedef n node;
  12.  
  13. int main ()
  14. {
  15.     node * root;
  16.     root = (node *)malloc(sizeof(node));
  17.     node * iter;
  18.     iter = root;
  19.     iter->x = 10;
  20.     iter->next = (node *)malloc(sizeof(node));
  21.     iter->next->x = 20;
  22.     iter->next->next = (node *)malloc(sizeof(node));
  23.     iter->next->next->x = 30;    
  24.     cout<<iter->x<<endl;
  25.     iter = iter->next;
  26.     cout<<iter->x<<endl;
  27.     iter = iter->next;
  28.     cout<<iter->x<<endl;
  29. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement