2024-11-11 20:35:40 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
|
|
#define SIZE 200
|
|
|
|
|
|
|
|
struct tree
|
|
|
|
{
|
2024-11-11 21:30:26 +00:00
|
|
|
|
2024-11-11 20:35:40 +00:00
|
|
|
char value[SIZE];
|
2024-11-11 21:10:54 +00:00
|
|
|
|
|
|
|
|
2024-11-11 20:35:40 +00:00
|
|
|
struct tree *left, *right;
|
|
|
|
};
|
|
|
|
|
2024-11-11 21:30:26 +00:00
|
|
|
struct tree* read_tree()
|
2024-11-11 20:35:40 +00:00
|
|
|
{
|
|
|
|
char buffer[SIZE];
|
|
|
|
memset(buffer,0,SIZE);
|
|
|
|
char* r = fgets(buffer,SIZE,stdin);
|
2024-11-11 21:30:26 +00:00
|
|
|
|
2024-11-11 20:35:40 +00:00
|
|
|
assert(r);
|
2024-11-11 21:10:54 +00:00
|
|
|
struct tree* node = (struct tree*)calloc(1,sizeof(struct tree));
|
2024-11-11 20:35:40 +00:00
|
|
|
memcpy(node->value,buffer,SIZE);
|
2024-11-11 21:30:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-11-11 21:10:54 +00:00
|
|
|
node->left=NULL;
|
|
|
|
node->right=NULL;
|
|
|
|
|
2024-11-11 20:35:40 +00:00
|
|
|
if(node->value[0]!='*')
|
|
|
|
{
|
2024-11-11 21:10:54 +00:00
|
|
|
|
2024-11-11 21:30:26 +00:00
|
|
|
node->left=read_tree(node->left);
|
|
|
|
|
|
|
|
node->right=read_tree(node->right);
|
2024-11-11 20:35:40 +00:00
|
|
|
}
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void print_tree(struct tree* tree,int offset){
|
|
|
|
for (int i = 0; i < offset; i++){
|
2024-11-11 21:10:54 +00:00
|
|
|
printf(".");
|
2024-11-11 20:35:40 +00:00
|
|
|
}
|
2024-11-11 21:30:26 +00:00
|
|
|
|
|
|
|
if(tree)
|
|
|
|
printf("%s",tree->value);
|
2024-11-11 20:35:40 +00:00
|
|
|
if (tree->left){
|
|
|
|
print_tree(tree->left,offset +3);
|
|
|
|
}
|
2024-11-11 21:10:54 +00:00
|
|
|
if (tree->right){
|
|
|
|
print_tree(tree->right,offset +3);
|
2024-11-11 20:35:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
2024-11-11 21:10:54 +00:00
|
|
|
|
|
|
|
struct tree *tr;
|
|
|
|
|
2024-11-11 21:30:26 +00:00
|
|
|
tr=read_tree();
|
|
|
|
|
2024-11-11 21:10:54 +00:00
|
|
|
print_tree(tr,3);
|
2024-11-11 21:30:26 +00:00
|
|
|
|
2024-11-11 20:35:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|