Update cv7/program.c
This commit is contained in:
parent
cba7e62977
commit
bf7202663e
@ -20,7 +20,11 @@ struct tree* read_tree()
|
||||
memset(buffer,0,SIZE);
|
||||
char* r = fgets(buffer,SIZE,stdin);
|
||||
|
||||
|
||||
assert(r);
|
||||
|
||||
if(buffer[0]=='\n')
|
||||
return NULL;
|
||||
struct tree* node = (struct tree*)calloc(1,sizeof(struct tree));
|
||||
memcpy(node->value,buffer,SIZE);
|
||||
|
||||
@ -53,6 +57,13 @@ void print_tree(struct tree* tree,int offset){
|
||||
}
|
||||
}
|
||||
|
||||
void destroy_tree(struct tree* tree){
|
||||
if(tree==NULL) return;
|
||||
|
||||
destroy_tree(tree->left);
|
||||
destroy_tree(tree->right);
|
||||
free(tree);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
@ -83,10 +94,9 @@ int main(void)
|
||||
|
||||
}while(1);
|
||||
|
||||
|
||||
printf("Koniec\n");
|
||||
destroy_tree(tr);
|
||||
tr=NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user