Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Node{
  6. public:
  7.     int v;
  8.     Node* next;
  9. };
  10.  
  11. void vuvod(Node*z){
  12.      while(z>0){
  13.           cout<<z->v<<endl;
  14.           z=(*z).next;
  15.      }
  16. }
  17.  
  18.  
  19. void push(Node** toot,int a){
  20.     Node*m=new Node;
  21.     m->v=a;
  22.     m->next=0;
  23.     *toot=m;
  24. }
  25.  
  26. int main()
  27. {
  28.  
  29.     Node*a=new Node;
  30.     Node*root=0;
  31.     Node*b=new Node;
  32.  
  33.     a->v=1;
  34.     a->next=root;
  35.     cout<<"push\n";
  36.  
  37.     push(&root,2);
  38.     b=root;
  39.     a->next=b;
  40.  
  41.     push(&root,3);
  42.     b->next=root;
  43.     b=root;
  44.  
  45.     push(&root,4);
  46.     b->next=root;
  47.     b=root;
  48.  
  49.     push(&root,5);
  50.     b->next=root;
  51.     b=root;
  52.  
  53.     vuvod(a);
  54.  
  55.     delete a;
  56.     delete b;
  57.     delete root;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement