Build Tree
Lição 6 de 13 do curso Árvore Binária - Série de Estruturas de Dados #3 da Coddy.
Desafio
FácilAdicione à BinaryTree um método buildTree que recebe uma representação de string recursiva da árvore ([value, leftSubtree, rightSubtree] com null para vazio) e constrói a árvore.
Experimente você mesmo
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "binarytree.h"
void rtl(Node* n) {
if (n == NULL) return;
printf("%d\n", Node_getValue(n));
rtl(Node_getRight(n));
rtl(Node_getLeft(n));
}
int main() {
char buf[4096];
if (!fgets(buf, sizeof(buf), stdin)) buf[0] = '\0';
buf[strcspn(buf, "\r\n")] = '\0';
BinaryTree bt;
BinaryTree_init(&bt);
BinaryTree_buildTree(&bt, buf);
rtl(BinaryTree_getRoot(&bt));
return 0;
}
Todas as lições de Árvore Binária - Série de Estruturas de Dados #3
2Binary Tree Project
Node ClassNode with Sons