diff --git a/a3/program.c b/a3/program.c new file mode 100644 index 0000000..33fe447 --- /dev/null +++ b/a3/program.c @@ -0,0 +1,57 @@ +#include + +int check(int i, int size, int array[]) +{ + if (i >= size) + { + return 0; + } + else if (array[i] < array[(i - 1) / 2]) + { + return 1; + } + else + { + return check(i * 2 + 1, size, array) + check(i * 2 + 2, size, array); + } +} + +int spaces = 0; +void print(int i, int size, int array[]) +{ + if(i >= size) + { + return; + } + for(int j = 0; j < spaces; j++) + { + printf(" "); + } + printf("%d\n", array[i]); + spaces = spaces + 1; + print(i * 2 + 1, size, array); + print(i * 2 + 2, size, array); + spaces = spaces - 1; +} + +int main() +{ + int array[1000]; + int size = 0; + while(scanf("%d", &array[size]) != EOF) + { + size++; + } + int result = check(0, size, array); + if (result == 0) + { + spaces = 0; + printf("Je to taka kopa:\n"); + print(0, size, array); + } + else + { + printf("Nie je kopa.\n"); + return 0; + } +} \ No newline at end of file