Erzkoy

histogram

Jan 15th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.79 KB | None | 0 0
  1. /******************************************************************************
  2.  
  3.                               Online C++ Compiler.
  4.                Code, Compile, Run and Debug C++ program online.
  5. Write your code in this editor and press "Run" button to compile and execute it.
  6.  
  7. *******************************************************************************/
  8.  
  9. #include <iostream>
  10. #include <cstdlib>
  11. using namespace std;
  12.  
  13. class kulka
  14. {
  15.     public:
  16.   kulka *next;
  17.   kulka *down;
  18.   int v;
  19.   kulka(int value):next(NULL),down(NULL),v(value){};
  20.   kulka():next(NULL),down(NULL),v(rand()%100){};
  21.  
  22.   void add_1(kulka *new_one)
  23.   {
  24.       if(down) down->add_1(new_one);
  25.       else  down=new_one;
  26.      
  27.   }
  28.   void show()
  29.   {
  30.       kulka *temp = this;
  31.       while(temp)
  32.       {
  33.           kulka *temp2 = temp;
  34.           while(temp2)
  35.           {
  36.              
  37.               cout<<temp2->v<<"  ";
  38.               temp2=temp2->next;
  39.           }
  40.           cout<<endl;
  41.          
  42.           temp=temp->down;
  43.       }
  44.   }
  45.  
  46.   void show2()
  47.   {
  48.       if(down) down->show2();
  49.       cout<<v<<"\t";
  50.       if(next) next->show2();
  51.   }
  52.  
  53.   void add_2(kulka *new_one)
  54.   {
  55.       if(new_one->v/10==v)
  56.       {
  57.           if(next==NULL) next=new_one;
  58.           else
  59.           {
  60.               new_one->next=next;
  61.               next=new_one;
  62.           }
  63.          
  64.          
  65.       }
  66.       else
  67.       {
  68.           down->add_2(new_one);
  69.       }
  70.      
  71.   }
  72.  
  73. };
  74.  
  75.  
  76. int main()
  77. {
  78.     kulka *root = new kulka(0);
  79.    
  80.     for(int i=1;i<10;i++)
  81.     {
  82.         kulka *new_one = new kulka(i);
  83.         root->add_1(new_one);
  84.        
  85.     }
  86.    
  87.     for(int i=0;i<90;i++)
  88.     {
  89.         kulka *new_one = new kulka;
  90.         root->add_2(new_one);
  91.     }
  92.     root->show();
  93.  
  94.     return 0;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment