Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- class kulka
- {
- public:
- kulka *l;
- kulka *p;
- int v;
- kulka():l(NULL),p(NULL),v(rand()%100+1){cout<<"K: "<<v<<" ";};
- void add_new(kulka *new_one)
- {
- if(new_one->v<v)
- {
- if(l==NULL)
- {
- l=new_one;
- }
- else
- {
- l->add_new(new_one);
- }
- }
- else
- {
- if(p==NULL)
- {
- p=new_one;
- }
- else
- {
- p->add_new(new_one);
- }
- }
- }
- void show()
- {
- if(l) l->show();
- cout<<v<<"\t";
- if(p) p->show();
- }
- };
- int main()
- {
- kulka *root = new kulka;
- for(int i=0;i<20;i++)
- {
- kulka *new_one = new kulka;
- root->add_new(new_one);
- }
- cout<<endl;
- root->show();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement