88 lines
1.6 KiB
C
88 lines
1.6 KiB
C
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <assert.h>
|
|
#include <ctype.h>
|
|
#include <stdbool.h>
|
|
|
|
void check_heap(int size, int* array){
|
|
int i;
|
|
for(i = 0; i < size; i++){
|
|
int c = (2 * i) + 1;
|
|
if(c >= size) break;
|
|
|
|
if(!(array[c] >= array[i])){
|
|
printf("Nie je to kopa.\n");
|
|
return;
|
|
}
|
|
|
|
c = (2 * i) + 2;
|
|
if(c >= size) break;
|
|
if(!(array[c] >= array[i])){
|
|
printf("Nie je to kopa.\n");
|
|
return;
|
|
}
|
|
|
|
}
|
|
printf("Je to kopa:\n");
|
|
|
|
}
|
|
|
|
|
|
void space(int l){
|
|
int i = 0;
|
|
for(i = 0; i < l; i++){
|
|
printf(" ");
|
|
}
|
|
|
|
}
|
|
|
|
void print(int *arr, int i, int size, int c, int level){
|
|
if(i >= size){
|
|
return;
|
|
}
|
|
space(level);
|
|
printf("%d\n", arr[i]);
|
|
print(arr,i*2+1, size, c, level+1);
|
|
|
|
print(arr, i*2+2, size, c, level+1);
|
|
}
|
|
|
|
|
|
int main() {
|
|
char* cisla = calloc(100, sizeof(char));
|
|
|
|
fgets(cisla, 100, stdin);
|
|
int size = cisla[strlen(cisla)-1];
|
|
int* num = calloc(size, sizeof(int));
|
|
char *end;
|
|
int i = 0;
|
|
while(i != size){
|
|
if(i == 0){
|
|
long int c = strtol(cisla, &end, 10);
|
|
num[i] = c;
|
|
|
|
}
|
|
else{
|
|
long int next = strtol(end, &end, 10);
|
|
num[i] = next;
|
|
}
|
|
i++;
|
|
|
|
}
|
|
i = 0;
|
|
int count = 0;
|
|
while(num[i] != 0){
|
|
count++;
|
|
i++;
|
|
}
|
|
i = 0;
|
|
int index = 0;
|
|
int l = 0;
|
|
int k = 36;
|
|
check_heap(count, num);
|
|
int j = 0;
|
|
print(num, index, count,num[0],l);
|
|
return 0;
|
|
}
|