Menu
Coddy logo textTech

BinaryTree Class

Lección 5 de 13 del curso Árbol Binario - Serie de Estructuras de Datos #3 de Coddy.

challenge icon

Desafío

Fácil

Escribe una clase BinaryTree con un constructor (que inicialice la raíz a null/None), getRoot y setRoot.

Pruébalo tú mismo

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "binarytree.h"

int main() {
    BinaryTree bt;
    BinaryTree_init(&bt);
    char line[256];
    while (fgets(line, sizeof(line), stdin)) {
        line[strcspn(line, "\r\n")] = '\0';
        char* cmd = strtok(line, " \t");
        if (!cmd) continue;
        if (strcmp(cmd, "setRoot") == 0) {
            char* arg = strtok(NULL, " \t");
            Node* c = Node_new();
            Node_setValue(c, atoi(arg));
            BinaryTree_setRoot(&bt, c);
        }
        if (strcmp(cmd, "getRootValue") == 0) {
            printf("%d\n", Node_getValue(BinaryTree_getRoot(&bt)));
        }
    }
    return 0;
}

Todas las lecciones de Árbol Binario - Serie de Estructuras de Datos #3