diff --git a/cv8/program.c b/cv8/program.c new file mode 100644 index 0000000..def3401 --- /dev/null +++ b/cv8/program.c @@ -0,0 +1,81 @@ +#include +#include +#include +#include +#define SIZE 100 + +typedef struct tree { + // Otázka aleo odpoveď + char value[SIZE]; + // Odpoveď áno + struct tree* left; + // Odpoveď nie + struct tree* right; +} tree; + +void print_tree(struct tree* node){ + if( node == NULL){ + printf("empty"); + return; + } + printf("hodnota: %s\n",node->value); + printf("left "); + printf("%s\n",node->left->value); + printf("right "); + printf("%s\n",node->right->value); + +} + +struct tree* read_tree(tree* node){ + char buffer[SIZE]; + memset(buffer,0, SIZE); + char* r = fgets(buffer, SIZE, stdin); + if( r == NULL ){ + return node; + } + memcpy(node->value, buffer, SIZE); + r = fgets(buffer, SIZE, stdin); + if( r == NULL ){ + node->left = NULL; + return node; + } + node->left = calloc(1, sizeof(struct tree)); + memcpy(node->left->value, buffer, SIZE); + r = fgets(buffer, SIZE, stdin); + if( r == NULL ){ + node->right = NULL; + return node; + } + node->right = calloc(1, sizeof(struct tree)); + memcpy(node->right->value, buffer, SIZE); + read_tree(node); + print_tree(node); + free(node); + return node; +} + +void guess(tree* node){ + + + +} +/*void remove_tree(struct tree* node){ + if ( node != NULL ){ + + if( node->left != NULL){ + remove_tree(node->left); + free(node); + } + if( node->right != NULL){ + remove_tree(node->right); + free(node); + } + } +}*/ + +int main(){ + tree* node = calloc(1, sizeof(struct tree)); + read_tree(node); + //remove_tree(node); +return 0; +}