usaa19cv9/program.c
2019-11-29 12:15:49 +01:00

62 lines
1.4 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#define SIZE 1000
struct node {
char question[SIZE];
struct node* left;
struct node* right;
};
//https://eli.thegreenplace.net/2009/11/23/visualizing-binary-trees-with-graphviz
void print_tree(struct node* tree,int offset){
for (int i = 0; i < offset; i++){
printf(" ");
}
printf("%s",tree->question);
if (tree->left){
print_tree(tree->left,offset +3);
print_tree(tree->right,offset +3);
}
}
struct node* read_tree(){
char buffer[SIZE];
memset(buffer,0,SIZE);
char * r = fgets(buffer,SIZE,stdin);
assert(r);
struct tree* node = calloc(1,sizeof(struct node));
memcpy(node->value,buffer,SIZE);
return node;
};
void traverse(struct node* tree){
}
int count_fruit(struct node* tree){
return 0;
}
void delete_tree(struct node* tree){
if (tree != NULL){
delete_tree(tree->left);
delete_tree(tree->right);
free(tree);
}
}
int main(){
printf("MUDrC to vie.\n");
struct node* tree = read_tree();
printf("Pozna %d druhov ovocia a zeleniny.\n",count_fruit(tree));
printf("Odpovedajte 'a' alebo 'n'\n");
traverse(tree);
delete_tree(tree);
}