Merge branch 'main' of git.kemt.fei.tuke.sk:ak643du/usaa24
This commit is contained in:
commit
28eee6e2c0
@ -1,6 +1,7 @@
|
|||||||
#include<stdio.h>
|
#include<stdio.h>
|
||||||
#include<string.h>
|
#include<string.h>
|
||||||
#include<assert.h>
|
#include<assert.h>
|
||||||
|
#include<stdlib.h>
|
||||||
|
|
||||||
#define SIZE 100
|
#define SIZE 100
|
||||||
|
|
||||||
@ -20,25 +21,26 @@ struct tree* read_tree(){
|
|||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct tstruct tree* load_tree() {
|
struct tree* load_tree() {
|
||||||
struct tree* tree = read_tree();
|
struct tree* node = read_tree();
|
||||||
|
if (!node) {
|
||||||
tree->left = load_tree();
|
return NULL;
|
||||||
tree->right = load_tree();
|
|
||||||
|
|
||||||
if (tree->value[0] == "*"){
|
|
||||||
re
|
|
||||||
}
|
}
|
||||||
|
if (node->value[0] != '*') {
|
||||||
|
node->left = load_tree();
|
||||||
|
node->right = load_tree();
|
||||||
|
}
|
||||||
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_tree(struct tree* tree,int offset){
|
void print_tree(struct tree* tree, int offset){
|
||||||
for (int i = 0; i < offset; i++){
|
for (int i = 0; i < offset; i++){
|
||||||
printf(" ");
|
printf(" ");
|
||||||
}
|
}
|
||||||
printf("%s",tree->question);
|
printf("%s", tree->value);
|
||||||
if (tree->left){
|
if (tree->left){
|
||||||
print_tree(tree->left,offset +3);
|
print_tree(tree->left, offset + 3);
|
||||||
print_tree(tree->right,offset +3);
|
print_tree(tree->right, offset + 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,18 +56,10 @@ 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->left == NULL && tree->right == NULL){
|
||||||
(*count)++
|
(*count)++;
|
||||||
}else{
|
}else{
|
||||||
count_items(tree->left, count);
|
count_items(tree->left, count);
|
||||||
count_items(tree->right, count);
|
count_items(tree->right, count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
|
||||||
printf("Constructing the tree:\n");
|
|
||||||
struct tree* root = test();
|
|
||||||
printf("The tree structure:\n");
|
|
||||||
print_tree(root, 0);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user