#include using namespace std; struct heap { int *dizi; int boyut; int indis; }; heap *tanimla(int n, int b) { heap *h = new heap; h->boyut = b; h->indis = 1; h->dizi = new int[h->boyut]; return h; } heap *insert(heap *h, int x) { if (h->indis == h->boyut) { cout << "heap dolu"; } else { h->dizi[h->indis] = x; int i = h->indis; h->indis++; while (i > 1 && h->dizi[i]>h->dizi[i/2]) { swap(h->dizi[i], h->dizi[i / 2]); i = i / 2; } } return h; } int del(heap *h) { if (h->indis == 1) cout << "heap bos"; else { int i = 1; int tmp = h->dizi[i]; h->indis--; h->dizi[i] = h->dizi[h->indis]; while (i*2 < h->indis && (h->dizi[i] < h->dizi[2 * i] || h->dizi[i] < h->dizi[2 * i + 1])) { if (h->dizi[2 * i] > h->dizi[2 * i + 1]) { swap(h->dizi[2 * i], h->dizi[i]); i = i * 2; } else { swap(h->dizi[2 * i + 1], h->dizi[i]); i = 2 * i + 1; } } return tmp; } } void sirali_empty(heap *h) { int *d1; d1 = new int[h->boyut]; int i = 1; int son = h->indis; while (i < son) { d1[i] = del(h); i++; } son--; while (son > 0) { cout << d1[son] << " "; son--; } } void print(heap *h) { if (h->indis == 1) cout << "heap bos"; else { int i = 1; while (i < h->indis) { cout << h->dizi[i] << " "; i++; } cout << endl; system("pause"); } } void main() { heap *h1; heap *h2; h1 = tanimla(1, 20); h2 = tanimla(2, 10); h1 = insert(h1, 35); h1 = insert(h1, 18); h1 = insert(h1, 42); h1 = insert(h1, 27); h1 = insert(h1, 52); h1 = insert(h1, 60); h1 = insert(h1, 67); h1 = insert(h1, 41); h1 = insert(h1, 55); h1 = insert(h1, 14); h1 = insert(h1, 8); h1 = insert(h1, 98); h1 = insert(h1, 86); h1 = insert(h1, 35); h1 = insert(h1, 24); h1 = insert(h1, 100); h1 = insert(h1, 12); h1 = insert(h1, 75); h1 = insert(h1, 47); print(h1); sirali_empty(h1); system("pause"); del(h1); print(h1); del(h1); print(h1); del(h1); print(h1); del(h1); print(h1); del(h1); print(h1); del(h1); print(h1); del(h1); print(h1); del(h1); print(h1); del(h1); print(h1); del(h1); print(h1); del(h1); print(h1); del(h1); print(h1); del(h1); print(h1); del(h1); print(h1); del(h1); print(h1); del(h1); print(h1); del(h1); print(h1); del(h1); print(h1); del(h1); print(h1); del(h1); print(h1); }