Update cv7/program.c

This commit is contained in:
Yurii Yakovenko 2024-11-11 22:28:18 +00:00
parent 8b4c6f2707
commit 63179fb088

View File

@ -4,7 +4,6 @@
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#define SIZE 200 #define SIZE 200
struct tree struct tree
@ -21,14 +20,14 @@ struct tree* read_tree()
char buffer[SIZE]; char buffer[SIZE];
memset(buffer,0,SIZE); memset(buffer,0,SIZE);
char* r = fgets(buffer,SIZE,stdin); char* r = fgets(buffer,SIZE,stdin);
assert(r); assert(r);
if(buffer[0]=='\n') if(buffer[0]=='\n')
return NULL; return NULL;
struct tree* node = (struct tree*)calloc(1,sizeof(struct tree)); struct tree* node = (struct tree*)calloc(1,sizeof(struct tree));
memcpy(node->value,buffer,SIZE); memcpy(node->value,buffer,SIZE);
node->left=NULL; node->left=NULL;
node->right=NULL; node->right=NULL;
@ -80,27 +79,31 @@ int main(void)
{ {
printf("%s",p->value); printf("%s",p->value);
if(p->value[0]=='*') if(p->value[0]=='*')
break; break;
do{
t=fgetc(stdin); t=fgetc(stdin);
if(t=='a') if(t=='a')
{ {
p=p->left; p=p->left; break;
} }
else if(t=='n') else if(t=='n')
{ {
p=p->right; p=p->right; break;
} }
else if(t!='\n') else if(t!='\n')
{ {
printf("Nerozumiem\n"); printf("Nerozumiem\n");
t=44;
break;
} }
}while(1);
}while(1); }while(t!=44);
printf("Koniec\n"); printf("Koniec\n");
destroy_tree(tr); destroy_tree(tr);
tr=NULL; tr=NULL;
return 0; return 0;
} }