#include #include #include int isMinHeap(int arr[], int len) { for (int i = 0; i <= (len - 2) / 2; i++) { int l = 2 * i + 1; int r = 2 * i + 2; if ((l < len && arr[i] > arr[l]) || (r < len && arr[i] > arr[r])) { return 0; } } return 1; } void printPreorder(int arr[], int len, int index, int level) { if (index >= len) { return; } for (int i = 0; i < level; i++) { printf(" "); } printf("%d\n", arr[index]); printPreorder(arr, len, 2 * index + 1, level + 1); printPreorder(arr, len, 2 * index + 2, level + 1); } int main() { char input[1000]; fgets(input, sizeof(input), stdin); int kopa[100]; int c = 0; char *token = strtok(input, " "); while (token != NULL) { kopa[c++] = atoi(token); token = strtok(NULL, " "); } if (isMinHeap(kopa, c)) { printf("Je to taka kopa:\n"); printPreorder(kopa, c, 0, 0); } else { printf("Nie je kopa.\n"); } return 0; }