2020-11-11 00:00:01 +00:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
|
|
#define SIZE 100
|
|
|
|
|
|
|
|
|
|
struct tree {
|
|
|
|
|
//otazka ab. odpoved
|
|
|
|
|
char value[SIZE];
|
2020-11-24 19:08:55 +00:00
|
|
|
|
// Odpove<76> <20>no
|
2020-11-11 00:00:01 +00:00
|
|
|
|
struct tree* left;
|
2020-11-24 19:08:55 +00:00
|
|
|
|
// Odpove<76> nie
|
2020-11-11 00:00:01 +00:00
|
|
|
|
struct tree* right;
|
2020-11-19 18:03:55 +00:00
|
|
|
|
}tree;
|
2020-11-11 00:00:01 +00:00
|
|
|
|
|
2020-11-19 18:03:55 +00:00
|
|
|
|
void print_tree(struct tree* tree,int offset){
|
2020-11-11 00:00:01 +00:00
|
|
|
|
for (int i = 0; i < offset; i++){
|
|
|
|
|
printf(" ");
|
|
|
|
|
}
|
2020-11-19 18:03:55 +00:00
|
|
|
|
printf("%s",tree->value);
|
2020-11-11 00:00:01 +00:00
|
|
|
|
if (tree->left){
|
|
|
|
|
print_tree(tree->left,offset +3);
|
|
|
|
|
print_tree(tree->right,offset +3);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void destroy_tree(struct tree* tree){
|
|
|
|
|
free(tree);
|
|
|
|
|
}
|
|
|
|
|
struct tree* read_tree(){
|
|
|
|
|
char buffer[SIZE];
|
|
|
|
|
memset(buffer,0,SIZE);
|
|
|
|
|
char* r = fgets(buffer,SIZE,stdin);
|
|
|
|
|
assert(r);
|
|
|
|
|
struct tree* node = calloc(1,sizeof(struct tree));
|
|
|
|
|
memcpy(node->value,buffer,SIZE);
|
|
|
|
|
// Ak je nacitany riadok listovy uzol ,tak netreba robit nic
|
|
|
|
|
// inak rekurzivne nacitanie laveho syna
|
|
|
|
|
// a rekurzivne nacitanie praveho syna
|
|
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
int main(){
|
2020-11-26 12:11:24 +00:00
|
|
|
|
printf("Expert z bufetu to vie.\n");
|
|
|
|
|
printf("Pozna 2 druhov ovocia a zeleniny.\n");
|
|
|
|
|
printf("Odpovedajte␣'a'␣pre␣prvu␣moznost␣alebo␣'n'␣pre␣druhu␣moznost.\n");
|
2020-11-26 12:13:05 +00:00
|
|
|
|
printf("Je to ovocie alebo zelenina ?\n");
|
2020-11-11 00:00:01 +00:00
|
|
|
|
/*int counter = 0;
|
|
|
|
|
int si = 0;
|
|
|
|
|
struct tree* stack[SIZE];
|
|
|
|
|
struct tree* this = tree;
|
|
|
|
|
while (si >= 0){
|
|
|
|
|
assert(si < SIZE);
|
|
|
|
|
if (this->left){
|
|
|
|
|
stack[si++] = this;
|
|
|
|
|
this = this->left;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
counter += 1;
|
|
|
|
|
if (this->right){
|
|
|
|
|
stack[si++] = this;
|
|
|
|
|
this = this->right;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
si = si -1;*/
|
|
|
|
|
return 0;
|
2020-11-19 18:03:55 +00:00
|
|
|
|
}
|