Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Heap::pop(int* &arr, int &size)
- {
- Stoper stoper;
- fstream file;
- do {
- file.open("kopiecUsun.txt", ios::app);
- if (file.good() != true)
- {
- cout << "Nieudane wczytywanie pliku!" << endl;
- cin.get();
- cin.get();
- }
- } while (file.good() != true);
- if (size == 1)
- {
- stoper.StartCounter();
- int *pom = new int;
- delete[] arr;
- arr = pom;
- size = 0;
- }
- else
- {
- stoper.StartCounter();
- arr[0] = arr[size - 1]; // ustawiam wartosc pierwszego elementu na wartosc ostatniego
- int *pom = new int[size - 1];
- for (int i = 0; i < size - 1; i++)
- pom[i] = arr[i];
- delete[] arr;
- arr = pom;
- size = size - 1;
- }
- if (size - 1)
- {
- int v = arr[0];
- int i = 0, j = 1;
- while (j < size)
- {
- if (j + 1 < size && arr[j + 1] > arr[j])
- j++;
- if (v >= arr[j])
- break;
- arr[i] = arr[j];
- i = j;
- j = 2 * j + 1;
- }
- arr[i] = v;
- }
- file << stoper.GetCounter() << endl;
- file.close();
- cout << "Zrobione!" << endl;
- cin.get();
- cin.get();
- system("cls");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement