This commit is contained in:
mr314ot 2025-11-21 08:28:25 +01:00
parent 6dfe6ba2bc
commit 35e328d9ff

View File

@ -10,6 +10,13 @@ typedef struct tree {
struct tree *right; struct tree *right;
} Tree; } Tree;
void strip_newline(char *s) {
int len = strlen(s);
if (len > 0 && s[len-1] == '\n') {
s[len-1] = '\0';
}
}
// rekurzivne nacitanie stromu v preorder // rekurzivne nacitanie stromu v preorder
Tree* read_tree() { Tree* read_tree() {
@ -60,18 +67,24 @@ int run_system(Tree *node) {
return 1; return 1;
} }
// list -> koniec char c[10];
printf("%s\n", node->value);
if (fgets(c, sizeof(c), stdin) == NULL) {
printf("Koniec vstupu\n");
return 0;
}
strip_newline(c);
if (!node->left && !node->right) { if (!node->left && !node->right) {
printf("Koniec vstupu\n"); printf("Koniec vstupu\n");
return 0; return 0;
} }
int c; if (strcmp(c,'a') == 0) {
if (c == 'a') {
if (node->left != NULL){ if (node->left != NULL){
return run_system(node->left); return run_system(node->left);
} }
} else if (c == 'n') { } else if (strcmp(c, 'n') == 0) {
if (node->right != NULL){ if (node->right != NULL){
return run_system(node->right); return run_system(node->right);
} }