t_btree *btree_insert_data(t_btree *root, void *data, size_t data_size, int (*cmpf)(void *, void *)) { if (!root) return (btree_create_node(data, data_size)); if ((*cmpf)(data, root->data) < 0) { if (root->left == 0) { root->left = btree_create_node(data, data_size); return (root->left); } btree_insert_data(root->left, data, data_size, cmpf); } else if ((*cmpf)(data, root->data) > 0) { if (root->right == 0) { root->right = btree_create_node(data, data_size); return (root->right); } btree_insert_data(root->right, data, data_size, cmpf); } return (root); }
extern p_btree_t btree_create(void) { p_btree_t tree_ret = NULL; tree_ret = (p_btree_t)malloc(sizeof(btree_t)); if (NULL == tree_ret) { errno = ENOMEM; return NULL; } tree_ret->root = btree_create_node(); if (NULL == tree_ret->root) { free(tree_ret); errno = ENOMEM; return NULL; } tree_ret->count = 0; tree_ret->root->data = NULL; tree_ret->root->lchild = NULL; tree_ret->root->rchild = NULL; return tree_ret; }
void btree_insert_data(t_btree **root, void *item, int (*cmpf)(void *, void *)) { if (*root == NULL) btree_create_node(item); else if ((*cmpf)(item, (*root)->item) < 0) btree_insert_data(&(*root)->left, item, cmpf); else btree_insert_data(&(*root)->right, item, cmpf); }
int main() { char *a = "aww ye"; t_btree *test_tree; test_tree = btree_create_node((void*)a); ft_putstr((char*)test_tree->item); return (0); }
t_btree *btree_add_left_node(t_btree **daddy, int value, int(*f_op)(int, int)) { t_btree *dnode; t_btree *node; node = btree_create_node(value, f_op); dnode = *daddy; if (dnode && node) dnode->left_son = node; return (node); }
void btree_insert_data(t_btree **root, void *item, int (*cmpf)(const char *, const char *)) { if (*root) if ((*cmpf)((*root)->item, item) >= 0) btree_insert_data(&(*root)->left, item, cmpf); else btree_insert_data(&(*root)->right, item, cmpf); else *root = btree_create_node(item); }
int main(void) { t_tree tree = NULL; t_tree left_sub_tree; unsigned int size; unsigned int depth; double max; double min; btree_create_node(&tree, 42.5); btree_create_node(&(tree->right), 100); btree_create_node(&(tree->left), 20); left_sub_tree = tree->left; btree_create_node(&(left_sub_tree->left), 30); btree_create_node(&(left_sub_tree->right), 5); size = btree_get_size(tree); //depth = btree_get_depth(tree); printf("L’arbre a une taille de %u\n", size); //printf("L’arbre a une profondeur de %u\n", depth); max = btree_get_max_value(tree); min = btree_get_min_value(tree); printf("Les valeurs de l’arbre vont de %f a %f\n", min, max); return (0); }
int eval_expr(char *str) { t_btree *root; int resultat; resultat = 0; str = ft_trim_space(str); root = btree_create_node(str); parse(root); resultat = calculate_parse(root); return (resultat); }
int main() { t_btree *root; t_btree *root1; t_btree *root2; t_btree *root3; t_btree *root4; t_btree *root5; root = btree_create_node("0"); root1 = btree_create_node("1"); root2 = btree_create_node("2"); root3 = btree_create_node("3"); root4 = btree_create_node("4"); root5 = btree_create_node("5"); root3->left = root2; root2->left = root1; root1->left = root; root3->right = root5; root5->left = root4; //printf("%d", btree_level_count(root3)); printf("%d\n",get_node_number(root3, 0)); return(0); }