du6 - 20
This commit is contained in:
parent
6dfe6ba2bc
commit
35e328d9ff
@ -10,6 +10,13 @@ typedef struct tree {
|
||||
struct tree *right;
|
||||
} 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
|
||||
Tree* read_tree() {
|
||||
@ -60,18 +67,24 @@ int run_system(Tree *node) {
|
||||
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) {
|
||||
printf("Koniec vstupu\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int c;
|
||||
if (c == 'a') {
|
||||
if (strcmp(c,'a') == 0) {
|
||||
if (node->left != NULL){
|
||||
return run_system(node->left);
|
||||
}
|
||||
} else if (c == 'n') {
|
||||
} else if (strcmp(c, 'n') == 0) {
|
||||
if (node->right != NULL){
|
||||
return run_system(node->right);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user