Aktualizovat du5/program.c

This commit is contained in:
Tomáš Vlček 2026-04-15 09:21:16 +00:00
parent 8d54f444ab
commit 8102459d0d

View File

@ -26,7 +26,8 @@ const int invalidIndex = -1;
// vytvorii binarny strom na zakl. vstupu
//** VRATI -> Bud cislo > 0 (Platny Koren) ALEBO stav '-1' (Neplatny index korenu, cize koniec stromu)
int buildATree() {
int buildATree()
{
if (indexLine >= lineCount)
{
return -1;
@ -49,7 +50,7 @@ int buildATree() {
tree[current].isAnswer = false;
strcpy(tree[current].text, line);
//rekurzivne vytvorii dalsie 'nodes' na na zaklade vycitanych odpovedi z standard inputu
//rekurzivne vytvorii dalsie 'nodes' (uzly po slovensky) na na zaklade vycitanych odpovedi z standard inputu
tree[current].yes = buildATree(); // 'a'
tree[current].no = buildATree(); // 'n'
@ -62,7 +63,6 @@ void goThroughTheTree(int rootIndex)
int current = rootIndex;
char input;
//
while (current != -1)
{
if (tree[current].isAnswer)
@ -73,6 +73,8 @@ void goThroughTheTree(int rootIndex)
}
printf("%s\n", tree[current].text);
//nacitanie odpovedi (jeden char)
scanf(" %c", &input);
if (input == 'a')
@ -95,7 +97,10 @@ int main()
{
char buffer[SIZE];
// Load input/
//null-terminovanie
buffer[0] = '\0';
// citanie vstupu
while (fgets(buffer, SIZE, stdin))
{
//prestane citat vstup, ak je NEPLATNY
@ -103,7 +108,7 @@ int main()
{
break;
}
//nahradi NewLine symbol za null terminator (Newline sa prida naspat potom na konci)
//nahradi NewLine symbol za null terminator (Newline sa prida naspat potom na konci programu)
for (int i = 0; i < SIZE; i++)
{
if (buffer[i] == '\n')
@ -115,6 +120,7 @@ int main()
strcpy(lines[lineCount], buffer);
}
//zisk. korena
int root = buildATree();
if (root == -1 || indexLine != lineCount) {