Update cv7/program.c

This commit is contained in:
Yurii Yakovenko 2024-11-11 22:19:11 +00:00
parent bf7202663e
commit 64bfb1ea96

View File

@ -4,13 +4,15 @@
#include <assert.h>
#include <string.h>
#define SIZE 200
struct tree
{
char value[SIZE];
struct tree *left, *right;
};
@ -19,23 +21,20 @@ struct tree* read_tree()
char buffer[SIZE];
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);
node->left=NULL;
node->right=NULL;
if(node->value[0]!='*')
{
node->left=read_tree(node->left);
{
node->left=read_tree(node->left);
node->right=read_tree(node->right);
}
return node;
@ -45,8 +44,7 @@ struct tree* read_tree()
void print_tree(struct tree* tree,int offset){
for (int i = 0; i < offset; i++){
printf(".");
}
}
if(tree)
printf("%s",tree->value);
if (tree->left){
@ -83,20 +81,27 @@ int main(void)
printf("%s",p->value);
if(p->value[0]=='*')
break;
do
t=fgetc(stdin);
if(t=='a')
{
t=fgetc(stdin);
if(t=='a')
{p=p->left; break;}
if(t=='n')
{p=p->right; break;}
}while(1);
p=p->left; break;
}
else if(t=='n')
{
p=p->right; break;
}
else
{
printf("Nerozumiem\n");
}
}while(1);
printf("Koniec\n");
destroy_tree(tr);
tr=NULL;
return 0;
}