SHARE
TWEET

Untitled

a guest Feb 20th, 2020 114 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<cstdio>
  4. #include<cmath>
  5.  
  6.  
  7. using namespace std;
  8.  
  9. class kulka
  10. {
  11.  
  12.     public:
  13.  
  14.     int i;
  15.  
  16.     kulka* prawy;
  17.     kulka* lewy;
  18.  
  19.  
  20.  
  21.     kulka()
  22.     {
  23.     i=rand()%100;
  24.     prawy=NULL;
  25.     lewy=NULL;
  26.     }
  27.  
  28.  
  29.  
  30. void show()
  31. {
  32.     if(lewy)
  33.     lewy->show();
  34.  
  35.     cout<<i<<endl;
  36.  
  37.     if(prawy)
  38.     prawy->show();
  39.    
  40. }
  41.  
  42. };
  43.  
  44.  
  45.  
  46.  
  47.  
  48. int main()
  49. {
  50.     kulka*root=new kulka();
  51.  
  52. for(int i=0; i<20; i++)
  53. {
  54. kulka*nowa = new kulka();
  55. bool znaleziona=false;
  56.  
  57. kulka* t=root;
  58.  
  59.     while(!znaleziona)
  60.     {
  61.         if(t->i < nowa->i)
  62.         {
  63.             if(t->prawy==NULL)
  64.             {
  65.                 t->prawy=nowa;
  66.                 znaleziona=true;
  67.             }
  68.             else
  69.             t=t->prawy;
  70.         }
  71.         else
  72.         {
  73.         if(t->lewy==NULL)
  74.         {
  75.             t->lewy=nowa;
  76.             znaleziona=true;
  77.         }
  78.         else
  79.         t=t->lewy;
  80.         }
  81.     }
  82. }
  83. root->show();
  84. return 0;
  85. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top