Advertisement
Guest User

Untitled

a guest
Mar 24th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. void Heap::pop(int* &arr, int &size)
  2. {
  3.     Stoper stoper;
  4.     fstream file;
  5.     do {
  6.         file.open("kopiecUsun.txt", ios::app);
  7.         if (file.good() != true)
  8.         {
  9.             cout << "Nieudane wczytywanie pliku!" << endl;
  10.             cin.get();
  11.             cin.get();
  12.         }
  13.     } while (file.good() != true);
  14.  
  15.     if (size == 1)
  16.     {
  17.         stoper.StartCounter();
  18.         int *pom = new int;
  19.         delete[] arr;
  20.         arr = pom;
  21.         size = 0;
  22.     }
  23.     else
  24.     {
  25.         stoper.StartCounter();
  26.         arr[0] = arr[size - 1]; // ustawiam wartosc pierwszego elementu na wartosc ostatniego
  27.         int *pom = new int[size - 1];
  28.         for (int i = 0; i < size - 1; i++)
  29.             pom[i] = arr[i];
  30.         delete[] arr;
  31.         arr = pom;
  32.         size = size - 1;
  33.     }
  34.  
  35.     if (size - 1)
  36.     {
  37.         int v = arr[0];
  38.         int i = 0, j = 1;
  39.         while (j < size)
  40.         {
  41.             if (j + 1 < size && arr[j + 1] > arr[j])
  42.                 j++;
  43.             if (v >= arr[j])
  44.                 break;
  45.             arr[i] = arr[j];
  46.             i = j;
  47.             j = 2 * j + 1;
  48.         }
  49.         arr[i] = v;
  50.     }
  51.     file << stoper.GetCounter() << endl;
  52.     file.close();
  53.     cout << "Zrobione!" << endl;
  54.     cin.get();
  55.     cin.get();
  56.     system("cls");
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement