Initializacia

This commit is contained in:
Kozar 2024-11-12 16:02:43 +00:00
parent 36f9d01893
commit 8d07713b65

View File

@ -1,6 +1,5 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#define SIZE 100 #define SIZE 100
@ -33,12 +32,8 @@ struct tree* load_tree() {
if (node->value[0] != '*') { if (node->value[0] != '*') {
node->left = load_tree(); node->left = load_tree();
node->right = load_tree(); node->right = load_tree();
} else {
node->left = NULL;
node->right = NULL;
} }
return node; return node;
}
void run_tree(struct tree* tree) { void run_tree(struct tree* tree) {
if (!tree) { if (!tree) {
@ -79,7 +74,9 @@ void destroy_tree(struct tree* tree) {
} }
void count_items(struct tree* tree, int* count) { void count_items(struct tree* tree, int* count) {
if (tree->left == NULL && tree->right == NULL) { if (!tree) return;
if (tree->value[0] == '*') {
(*count)++; (*count)++;
} else { } else {
if (tree->left) count_items(tree->left, count); if (tree->left) count_items(tree->left, count);
@ -90,6 +87,7 @@ void count_items(struct tree* tree, int* count) {
int main() { int main() {
struct tree* root = load_tree(); struct tree* root = load_tree();
printf("Expert z bufetu to vie.\n"); printf("Expert z bufetu to vie.\n");
if (!root) { if (!root) {
printf("Chybna databaza\n"); printf("Chybna databaza\n");
return 0; return 0;