commit
This commit is contained in:
parent
6eab61c530
commit
47805e95d4
@ -26,11 +26,9 @@ struct Node* read_tree(void) {
|
|||||||
struct Node* node = calloc(1, sizeof(struct Node));
|
struct Node* node = calloc(1, sizeof(struct Node));
|
||||||
if (node == NULL) return NULL;
|
if (node == NULL) return NULL;
|
||||||
strcpy(node->value, buffer);
|
strcpy(node->value, buffer);
|
||||||
|
|
||||||
if (buffer[0] != '*') {
|
if (buffer[0] != '*') {
|
||||||
node->left = read_tree();
|
node->left = read_tree();
|
||||||
node->right = read_tree();
|
node->right = read_tree();
|
||||||
|
|
||||||
if (node->left == NULL || node->right == NULL) {
|
if (node->left == NULL || node->right == NULL) {
|
||||||
destroy_tree(node);
|
destroy_tree(node);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -48,15 +46,16 @@ int count_leaves(const struct Node* node) {
|
|||||||
void run_system(struct Node* node) {
|
void run_system(struct Node* node) {
|
||||||
if (node == NULL) return;
|
if (node == NULL) return;
|
||||||
printf("%s", node->value);
|
printf("%s", node->value);
|
||||||
|
|
||||||
if (node->left == NULL && node->right == NULL) {
|
if (node->left == NULL && node->right == NULL) {
|
||||||
printf("Koniec vstupu\n");
|
printf("Koniec vstupu\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
char answer[SIZE];
|
char answer[SIZE];
|
||||||
if (fgets(answer, SIZE, stdin) == NULL) return;
|
if (fgets(answer, SIZE, stdin) == NULL) {
|
||||||
|
printf("Koniec vstupu\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
answer[strcspn(answer, "\r\n")] = '\0';
|
answer[strcspn(answer, "\r\n")] = '\0';
|
||||||
|
|
||||||
if (strcmp(answer, "a") == 0) {
|
if (strcmp(answer, "a") == 0) {
|
||||||
run_system(node->left);
|
run_system(node->left);
|
||||||
} else if (strcmp(answer, "n") == 0) {
|
} else if (strcmp(answer, "n") == 0) {
|
||||||
@ -74,15 +73,12 @@ int main(void) {
|
|||||||
}
|
}
|
||||||
char sep[SIZE];
|
char sep[SIZE];
|
||||||
fgets(sep, SIZE, stdin);
|
fgets(sep, SIZE, stdin);
|
||||||
|
|
||||||
int leaves = count_leaves(root);
|
int leaves = count_leaves(root);
|
||||||
printf("Expert z bufetu to vie.\n");
|
printf("Expert z bufetu to vie.\n");
|
||||||
printf("Pozna %d druhov ovocia a zeleniny.\n", leaves);
|
printf("Pozna %d druhov ovocia a zeleniny.\n", leaves);
|
||||||
printf("Odpovedajte 'a' pre prvu moznost alebo 'n' pre druhu moznost.\n");
|
printf("Odpovedajte 'a' pre prvu moznost alebo 'n' pre druhu moznost.\n");
|
||||||
printf("Je to ovocie alebo zelenina.\n");
|
|
||||||
|
|
||||||
run_system(root);
|
run_system(root);
|
||||||
|
|
||||||
destroy_tree(root);
|
destroy_tree(root);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user