#include <stdio.h>
int main() {
int arr[] = {60,33,44,55,69,33,75};
int n = sizeof(arr) / sizeof(arr[0]);
for (int i = n / 2 - 1; i >= 0; i--) {
int largest = i;
int l = 2 * i + 1;
int r = 2 * i + 2;
if (l < n && arr[l] > arr[largest]) {
largest = l;
}
if (r < n && arr[r] > arr[largest]) {
largest = r;
}
if (largest != i) {
int temp = arr[i];
arr[i] = arr[largest];
arr[largest] = temp;
i = n;
}
}
printf("Heap before deleting root:\n");
for (int i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
printf("\n");
if (n > 0) {
arr[0] = arr[n - 1];
n--;
int i = 0;
while (i < n) {
int largest = i;
int l = 2 * i + 1;
int r = 2 * i + 2;
if (l < n && arr[l] > arr[largest]) {
largest = l;
}
if (r < n && arr[r] > arr[largest]) {
largest = r;
}
if (largest != i) {
int temp = arr[i];
arr[i] = arr[largest];
arr[largest] = temp;
i = largest;
} else {
break;
}
}
}
printf("Heap after deleting root:\n");
for (int i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
printf("\n");
return 0;
}