cv7
This commit is contained in:
parent
5d4e3c95b5
commit
deaaf957f5
41
cv7/program.c
Normal file
41
cv7/program.c
Normal 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
BIN
cv7/program.exe
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user