cv7
This commit is contained in:
parent
ab7d4d65fd
commit
ef5fd01176
@ -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);
|
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)
|
if (node == NULL)
|
||||||
{
|
{
|
||||||
@ -92,7 +92,6 @@ void interact(struct tree *node)
|
|||||||
char answer[SIZE];
|
char answer[SIZE];
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (fgets(answer, sizeof(answer), stdin) == NULL)
|
if (fgets(answer, sizeof(answer), stdin) == NULL)
|
||||||
{
|
{
|
||||||
printf("Koniec vstupu\n");
|
printf("Koniec vstupu\n");
|
||||||
@ -101,24 +100,33 @@ void interact(struct tree *node)
|
|||||||
|
|
||||||
size_t len = strlen(answer);
|
size_t len = strlen(answer);
|
||||||
|
|
||||||
if (answer[len - 1] == '\n') {
|
if (answer[len - 1] == '\n')
|
||||||
|
{
|
||||||
answer[len - 1] = '\0';
|
answer[len - 1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen(answer) != 1 || (answer[0] != 'a' && answer[0] != 'n'))
|
if (strlen(answer) != 1 || (answer[0] != 'a' && answer[0] != 'n'))
|
||||||
{
|
{
|
||||||
printf("Nerozumiem\n");
|
if(fstenter == 0)
|
||||||
break;
|
{
|
||||||
|
fstenter = 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("Nerozumiem\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (answer[0] == 'a')
|
if (answer[0] == 'a')
|
||||||
{
|
{
|
||||||
interact(node->left);
|
interact(node->left, fstenter);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (answer[0] == 'n')
|
else if (answer[0] == 'n')
|
||||||
{
|
{
|
||||||
interact(node->right);
|
interact(node->right, fstenter);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,6 +136,7 @@ void interact(struct tree *node)
|
|||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
struct tree *root = read_tree();
|
struct tree *root = read_tree();
|
||||||
|
//getchar();
|
||||||
int leafs = count_leaf_nodes(root);
|
int leafs = count_leaf_nodes(root);
|
||||||
if(leafs == 0)
|
if(leafs == 0)
|
||||||
{
|
{
|
||||||
@ -142,8 +151,8 @@ int main()
|
|||||||
printf("Chyba pri nacitani databazy pravidiel.\n");
|
printf("Chyba pri nacitani databazy pravidiel.\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
int fstenter = 0;
|
||||||
interact(root);
|
interact(root, fstenter);
|
||||||
free_tree(root);
|
free_tree(root);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user