Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <time.h>
- #include <stdio.h>
- int n=0;
- using namespace std;
- void dodaj_elemet_do_kopca(int *tab, int wartosc)
- {
- cout << wartosc << endl;
- int i,j;
- i = n++;
- j = (i - 1) / 2;
- while(i > 0 && tab[j] < wartosc)
- {
- tab[i] = tab[j];
- i = j;
- j = (i - 1) / 2;
- }
- tab[i] = wartosc;
- }
- void wyswietl_kopiec(int *T, int v)
- {
- if(v < n)
- {
- wyswietl_kopiec(T, 2 * v + 2);
- cout << T[v] << endl;
- wyswietl_kopiec(T, 2 * v + 1);
- }
- }
- int main()
- {
- int *tab;
- tab=new int;
- int wybor;
- srand(time(NULL));
- do
- {
- cout << "Co zrobic?" << endl;
- cout << "1. Dodaj losowy element" << endl;
- cout << "2. Wyswietl drzewo" << endl;
- cout << "4. Wyjscie" << endl;
- cin >> wybor;
- cout << endl << endl;
- switch(wybor){
- case 1: dodaj_elemet_do_kopca(tab, rand()%75); break;
- case 2:
- {
- wyswietl_kopiec(tab, 0);
- break;
- }
- case 4: break;
- default : cout << "bledny wybor" << endl; break;
- }
- }
- while (wybor != 4);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment