Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<ctime>
- using namespace std;
- class Kulka
- {
- int numerT, numerL;
- public:
- Kulka* next;
- Kulka* right;
- Kulka* left;
- Kulka(int i)
- {
- numerT = i;
- numerL = rand() % 100;
- left = right = next = NULL;
- }
- void wstaw_l(Kulka* w)
- {
- if (next == NULL)next = w;
- else
- {
- if (next->numerL > w->numerL)
- {
- w->next = next;
- next = w;
- numerT++;
- }
- else
- {
- next->wstaw_l(w);
- }
- }
- }
- void wstaw_d(Kulka* w)
- {
- if (numerL > w->numerL)
- {
- if (left)left->wstaw_d(w);
- else left = w;
- }
- else
- {
- if (right)right->wstaw_d(w);
- else right = w;
- }
- }
- void wyswietl_l()
- {
- Kulka* pom = this;
- while (pom)
- {
- cout << "Lista " << " numerL " << pom->numerL << " numerT " << pom->numerT << endl;
- pom = pom->next;
- }
- }
- void wyswietl_d()
- {
- if (left)left->wyswietl_d();
- cout << "Drzewo" << " numerL " << numerL << " numerT " << numerT << endl;
- if (right)right->wyswietl_d();
- }
- int return_numerL() { return numerL; }
- };
- int main()
- {
- srand(time(NULL));
- Kulka* r_l_P = NULL;
- Kulka* r_l_N = NULL;
- for (int i = 0; i < 10; i++)
- {
- Kulka* w = new Kulka(i);
- if (w->return_numerL() % 2 == 0)
- {
- if(!r_l_P )r_l_P = w;
- else
- {
- if (r_l_P->return_numerL() > w->return_numerL())
- {
- w->next = r_l_P;
- r_l_P = w;
- }
- else
- {
- r_l_P->wstaw_l(w);
- }
- }
- }
- else
- {
- if (!r_l_N)r_l_N = w;
- else
- {
- if (r_l_N->return_numerL() > w->return_numerL())
- {
- w->next = r_l_N;
- r_l_N= w;
- }
- else
- {
- r_l_N->wstaw_l(w);
- }
- }
- }
- }
- r_l_N->wyswietl_l();
- cout << "Parzysta ::" << endl;
- r_l_P->wyswietl_l();
- Kulka* r_d = NULL;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement