Update 'cv8/program.c'

This commit is contained in:
Anzhelika Nikolaieva 2023-11-24 22:14:16 +00:00
parent 1f68678676
commit b488232679

View File

@ -3,7 +3,6 @@
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#define SIZE 256 #define SIZE 256
struct tree { struct tree {
@ -12,7 +11,6 @@ struct tree {
struct tree* right; struct tree* right;
}; };
struct tree* read_tree(int* counter); struct tree* read_tree(int* counter);
void destroy_tree(struct tree* tree); void destroy_tree(struct tree* tree);
void print_tree(struct tree* tree, int offset); void print_tree(struct tree* tree, int offset);
@ -43,14 +41,14 @@ struct tree* read_tree(int* counter) {
void destroy_tree(struct tree* tree) { void destroy_tree(struct tree* tree) {
if (tree) { if (tree) {
destroy_tree(tree->left); destroy_tree(tree->left);
destroy_tree(tree->right); destroy_tree(tree->right);
free(tree); free(tree);
} }
} }
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->v); printf("%s", tree->v);
if (tree->left) { if (tree->left) {
@ -96,17 +94,17 @@ void knowledge_system(struct tree* node) {
return; return;
} }
printf("%s", node->v);
if (node->left == NULL && node->right == NULL) { if (node->left == NULL && node->right == NULL) {
printf("%s", node->v);
printf("Koniec\n"); printf("Koniec\n");
return; return;
} }
printf("%s", node->v);
printf("Odpovedajte 'a' pre prvu moznost alebo 'n' pre druhu moznost.\n"); printf("Odpovedajte 'a' pre prvu moznost alebo 'n' pre druhu moznost.\n");
char response; char response;
do { do {
printf("%s", node->v);
scanf(" %c", &response); scanf(" %c", &response);
if (response != 'a' && response != 'n') { if (response != 'a' && response != 'n') {
printf("Nespravny vstup\n"); printf("Nespravny vstup\n");
@ -123,7 +121,7 @@ void knowledge_system(struct tree* node) {
int main() { int main() {
printf("Expert z bufetu to vie.\n"); printf("Expert z bufetu to vie.\n");
int counter = 0; int counter = 0;
struct tree* root = read_tree(&counter); struct tree* root = read_tree(&counter);