Initializacia
This commit is contained in:
parent
36f9d01893
commit
8d07713b65
@ -1,6 +1,5 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define SIZE 100
|
||||
@ -18,7 +17,7 @@ struct tree* read_tree() {
|
||||
if (!r || buffer[0] == '\n') {
|
||||
return NULL;
|
||||
}
|
||||
buffer[strcspn(buffer, "\n")] = 0;
|
||||
buffer[strcspn(buffer, "\n")] = 0;
|
||||
struct tree* node = calloc(1, sizeof(struct tree));
|
||||
strncpy(node->value, buffer, SIZE - 1);
|
||||
return node;
|
||||
@ -30,15 +29,11 @@ struct tree* load_tree() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (node->value[0] != '*') {
|
||||
if (node->value[0] != '*') {
|
||||
node->left = load_tree();
|
||||
node->right = load_tree();
|
||||
} else {
|
||||
node->left = NULL;
|
||||
node->right = NULL;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
return node;
|
||||
|
||||
void run_tree(struct tree* tree) {
|
||||
if (!tree) {
|
||||
@ -46,11 +41,11 @@ void run_tree(struct tree* tree) {
|
||||
}
|
||||
|
||||
if (tree->value[0] == '*') {
|
||||
printf("%s\nKoniec\n", tree->value + 1);
|
||||
printf("%s\nKoniec\n", tree->value + 1);
|
||||
return;
|
||||
}
|
||||
|
||||
printf("%s\n", tree->value);
|
||||
printf("%s\n", tree->value);
|
||||
|
||||
char response;
|
||||
if (scanf(" %c", &response) != 1) {
|
||||
@ -79,7 +74,9 @@ void destroy_tree(struct tree* tree) {
|
||||
}
|
||||
|
||||
void count_items(struct tree* tree, int* count) {
|
||||
if (tree->left == NULL && tree->right == NULL) {
|
||||
if (!tree) return;
|
||||
|
||||
if (tree->value[0] == '*') {
|
||||
(*count)++;
|
||||
} else {
|
||||
if (tree->left) count_items(tree->left, count);
|
||||
@ -90,6 +87,7 @@ void count_items(struct tree* tree, int* count) {
|
||||
int main() {
|
||||
struct tree* root = load_tree();
|
||||
printf("Expert z bufetu to vie.\n");
|
||||
|
||||
if (!root) {
|
||||
printf("Chybna databaza\n");
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user