This commit is contained in:
Ivan Leichenko 2024-11-15 07:07:10 +01:00
parent ab7d4d65fd
commit ef5fd01176

View File

@ -73,7 +73,7 @@ int count_non_leaf_nodes(struct tree *node)
return 1 + count_non_leaf_nodes(node->left) + count_non_leaf_nodes(node->right);
}
void interact(struct tree *node)
void interact(struct tree *node, int fstenter)
{
if (node == NULL)
{
@ -92,7 +92,6 @@ void interact(struct tree *node)
char answer[SIZE];
while (1)
{
if (fgets(answer, sizeof(answer), stdin) == NULL)
{
printf("Koniec vstupu\n");
@ -101,24 +100,33 @@ void interact(struct tree *node)
size_t len = strlen(answer);
if (answer[len - 1] == '\n') {
if (answer[len - 1] == '\n')
{
answer[len - 1] = '\0';
}
if (strlen(answer) != 1 || (answer[0] != 'a' && answer[0] != 'n'))
{
printf("Nerozumiem\n");
break;
if(fstenter == 0)
{
fstenter = 1;
continue;
}
else
{
printf("Nerozumiem\n");
return;
}
}
if (answer[0] == 'a')
{
interact(node->left);
interact(node->left, fstenter);
return;
}
else if (answer[0] == 'n')
{
interact(node->right);
interact(node->right, fstenter);
return;
}
@ -128,6 +136,7 @@ void interact(struct tree *node)
int main()
{
struct tree *root = read_tree();
//getchar();
int leafs = count_leaf_nodes(root);
if(leafs == 0)
{
@ -142,8 +151,8 @@ int main()
printf("Chyba pri nacitani databazy pravidiel.\n");
return 1;
}
interact(root);
int fstenter = 0;
interact(root, fstenter);
free_tree(root);
return 0;