Aktualizovat du6/program.c
This commit is contained in:
parent
bf691cbf9a
commit
a60719b45d
@ -37,7 +37,7 @@ struct tree* read_tree(int* counter) {
|
|||||||
strcpy(node->value, buffer);
|
strcpy(node->value, buffer);
|
||||||
node->id = (*counter)++;
|
node->id = (*counter)++;
|
||||||
|
|
||||||
// відповідь (*...), то це лист → не читаємо дітей
|
//відповідь (*.), то це лист → не читаємо дітей
|
||||||
if (buffer[0] == '*') {
|
if (buffer[0] == '*') {
|
||||||
node->left = NULL;
|
node->left = NULL;
|
||||||
node->right = NULL;
|
node->right = NULL;
|
||||||
@ -52,7 +52,7 @@ struct tree* read_tree(int* counter) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void destroy_tree(struct tree* node) {
|
void destroy_tree(struct tree* node) {
|
||||||
if (!node) return; // якщо вузла немає → нічого робити
|
if (!node) return; //якщо вузла немає → нічого робити
|
||||||
|
|
||||||
destroy_tree(node->left);
|
destroy_tree(node->left);
|
||||||
destroy_tree(node->right);
|
destroy_tree(node->right);
|
||||||
@ -61,9 +61,9 @@ void destroy_tree(struct tree* node) {
|
|||||||
|
|
||||||
|
|
||||||
int count_leaves(struct tree* node) {
|
int count_leaves(struct tree* node) {
|
||||||
if (!node) return 0; // порожнє дерево
|
if (!node) return 0; //порожнє дерево
|
||||||
|
|
||||||
if (!node->left && !node->right) // якщо це лист
|
if (!node->left && !node->right) //якщо це лист
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
return count_leaves(node->left)+count_leaves(node->right);
|
return count_leaves(node->left)+count_leaves(node->right);
|
||||||
@ -73,7 +73,7 @@ int count_leaves(struct tree* node) {
|
|||||||
void run_system(struct tree* node) {
|
void run_system(struct tree* node) {
|
||||||
while (node) {
|
while (node) {
|
||||||
printf("Odpovedajte 'a' pre prvu moznost alebo 'n' pre druhu moznost.\n");
|
printf("Odpovedajte 'a' pre prvu moznost alebo 'n' pre druhu moznost.\n");
|
||||||
printf("%s\n", node->value); // виводимо питання або відповідь
|
printf("%s\n", node->value); //виводимо питання чи відповідь
|
||||||
|
|
||||||
if (!node->left && !node->right) {
|
if (!node->left && !node->right) {
|
||||||
printf("Koniec\n");
|
printf("Koniec\n");
|
||||||
@ -87,9 +87,9 @@ void run_system(struct tree* node) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c == 'a') // так → йдемо в ліву гілку
|
if (c == 'a') //так → йдемо в ліву гілку
|
||||||
node = node->left;
|
node = node->left;
|
||||||
else if (c == 'n') // ні → вправо
|
else if (c == 'n') //ні → вправо
|
||||||
node = node->right;
|
node = node->right;
|
||||||
else {
|
else {
|
||||||
printf("Nespravny vstup.\n");
|
printf("Nespravny vstup.\n");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user