usaa19cv9/program.c

62 lines
1.4 KiB
C
Raw Normal View History

2019-11-29 00:09:31 +00:00
#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(){
2019-11-29 11:14:45 +00:00
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);
2019-11-29 11:16:27 +00:00
return *node;
2019-11-29 11:15:49 +00:00
};
2019-11-29 00:09:31 +00:00
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");
2019-11-29 11:14:45 +00:00
traverse(tree);
2019-11-29 00:09:31 +00:00
delete_tree(tree);
}