This commit is contained in:
mr314ot 2025-11-17 10:23:41 +01:00
parent afd5c9cdee
commit f2155d74d7

View File

@ -10,6 +10,8 @@ typedef struct tree {
struct tree *right; struct tree *right;
} Tree; } Tree;
int valid_db = 1;
//odstranit koncovy znak //odstranit koncovy znak
void strip_newline(char *s) { void strip_newline(char *s) {
int len = strlen(s); int len = strlen(s);
@ -43,6 +45,7 @@ Tree* read_tree() {
// inak nacitat oboch potomkov // inak nacitat oboch potomkov
node->left = read_tree(); node->left = read_tree();
if (!node->left) { if (!node->left) {
valid_db = 0;
free(node); free(node);
return NULL; return NULL;
} }
@ -50,6 +53,7 @@ Tree* read_tree() {
node->right = read_tree(); node->right = read_tree();
if (!node->right) { if (!node->right) {
free(node->left); free(node->left);
valid_db = 0;
free(node); free(node);
return NULL; return NULL;
} }
@ -75,6 +79,8 @@ int count_leaves(Tree *t) {
// spustenie znalostneho systemu // spustenie znalostneho systemu
void run_system(Tree *node) { void run_system(Tree *node) {
if (!node) return;
printf("%s\n", node->value); printf("%s\n", node->value);
// list -> koniec // list -> koniec
@ -106,7 +112,7 @@ int main() {
Tree *root = read_tree(); Tree *root = read_tree();
// nepodarilo sa nacitat koren -> chyba // nepodarilo sa nacitat koren -> chyba
if (!root) { if (!root || !valid_db) {
printf("Expert z bufetu to vie.\n"); printf("Expert z bufetu to vie.\n");
printf("Chybna databaza\n"); printf("Chybna databaza\n");
return 0; return 0;