2020-11-29 21:06:52 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
2020-11-30 11:49:20 +00:00
|
|
|
void check_heap(int size, long int* array){
|
2020-11-29 21:06:52 +00:00
|
|
|
int i;
|
|
|
|
for(i = 0; i < size; i++){
|
|
|
|
int c = (2 * i) + 1;
|
|
|
|
if(c >= size) break;
|
|
|
|
|
|
|
|
if(!(array[c] >= array[i])){
|
2020-11-29 21:11:56 +00:00
|
|
|
printf("Nie je kopa.\n");
|
2020-11-29 21:11:23 +00:00
|
|
|
exit(0);
|
2020-11-29 21:06:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
c = (2 * i) + 2;
|
|
|
|
if(c >= size) break;
|
|
|
|
if(!(array[c] >= array[i])){
|
2020-11-29 21:12:32 +00:00
|
|
|
printf("Nie je kopa.\n");
|
2020-11-29 21:10:50 +00:00
|
|
|
exit(0);
|
2020-11-29 21:06:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-11-29 21:08:11 +00:00
|
|
|
printf("Je to taka kopa:\n");
|
2020-11-29 21:06:52 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void space(int l){
|
|
|
|
int i = 0;
|
|
|
|
for(i = 0; i < l; i++){
|
|
|
|
printf(" ");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-11-30 11:49:20 +00:00
|
|
|
void print(long int *arr, int i, int size, int c, int level){
|
2020-11-29 21:06:52 +00:00
|
|
|
if(i >= size){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
space(level);
|
2020-11-30 11:49:20 +00:00
|
|
|
printf("%ld\n", arr[i]);
|
2020-11-29 21:06:52 +00:00
|
|
|
print(arr,i*2+1, size, c, level+1);
|
|
|
|
|
|
|
|
print(arr, i*2+2, size, c, level+1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main() {
|
2020-11-30 11:49:20 +00:00
|
|
|
char cisla[100];
|
|
|
|
|
|
|
|
char *r = fgets(cisla, 100, stdin);
|
|
|
|
if(r == NULL){
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
cisla[strlen(cisla)-1] = '\0';
|
|
|
|
int size = strlen(cisla);
|
|
|
|
|
|
|
|
long int num[size];
|
2020-11-29 21:06:52 +00:00
|
|
|
|
|
|
|
char *end;
|
|
|
|
int i = 0;
|
|
|
|
while(i != size){
|
|
|
|
if(i == 0){
|
|
|
|
long int c = strtol(cisla, &end, 10);
|
|
|
|
num[i] = c;
|
2020-11-30 11:49:20 +00:00
|
|
|
|
2020-11-29 21:06:52 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
long int next = strtol(end, &end, 10);
|
|
|
|
num[i] = next;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
|
|
|
|
}
|
|
|
|
i = 0;
|
|
|
|
int count = 0;
|
2020-11-30 11:49:20 +00:00
|
|
|
while(num[i] != '\0'){
|
2020-11-29 21:06:52 +00:00
|
|
|
count++;
|
2020-11-30 11:49:20 +00:00
|
|
|
i++;
|
2020-11-29 21:06:52 +00:00
|
|
|
}
|
2020-11-30 11:49:20 +00:00
|
|
|
|
2020-11-29 21:06:52 +00:00
|
|
|
i = 0;
|
|
|
|
int index = 0;
|
|
|
|
int l = 0;
|
|
|
|
check_heap(count, num);
|
|
|
|
int j = 0;
|
|
|
|
print(num, index, count,num[0],l);
|
2020-11-30 11:49:20 +00:00
|
|
|
|
2020-11-29 21:06:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|