first commit

This commit is contained in:
Valér Jakubčo 2021-11-25 02:36:11 +01:00
parent ccab180860
commit b8fa664a33

81
cv8/program.c Normal file
View File

@ -0,0 +1,81 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#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;
}