This commit is contained in:
Bohdan Kapliuk 2024-11-05 14:48:20 +02:00
parent 5d4e3c95b5
commit deaaf957f5
2 changed files with 41 additions and 0 deletions

41
cv7/program.c Normal file
View File

@ -0,0 +1,41 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#define SIZE 100
struct tree {
char* value;
struct tree* left;
struct tree* right;
};
struct tree* read_tree(){
char buffer[SIZE];
memset(buffer, 0, SIZE);
char* r = fgets(buffer, SIZE, stdin);
if(buffer[0] == '\n'){
return NULL;
}
assert(r);
struct tree* node = calloc(1, sizeof(struct tree));
node->value = malloc(strlen(buffer) + 1);
assert(node->value);
node->left = read_tree();
node->right = read_tree();
return node;
}
void destroy_tree(struct tree* node) {
if (node == NULL) return;
destroy_tree(node->left);
destroy_tree(node->right);
free(node);
}
int main(){
struct tree* root = read_tree();
read_tree();
destroy_tree(root);
return 0;
}

BIN
cv7/program.exe Normal file

Binary file not shown.