int main() { nAryTree tree; int root = 0; initializeTree(&tree, sizeof(int), &root); int infoChild = 1; add_child(&tree, &root, &infoChild, compare_int); infoChild = 2; add_child(&tree, &root, &infoChild, compare_int); infoChild = 3; add_child(&tree, &root, &infoChild, compare_int); root = 2; infoChild = 4; add_child(&tree, &root, &infoChild, compare_int); print_pre_order(&tree, print_integer); printf("\n"); int nodeThatShallBeRemoved = 1; Node removed; remove_node(&tree,&nodeThatShallBeRemoved,&removed, compare_int); print_pre_order(&tree, print_integer); return 0; }
/* Preorder (Root, Left, Right) : 7 4 1 6 8 */ void print_pre_order(struct node *head) { if(head == NULL) return; printf("%d \t", head->value); if(head->left) print_pre_order(head->left); if(head->right) print_pre_order(head->right); return; }
int main(int argc, char const *argv[]) { struct node *temp = NULL; struct node *head = NULL; head = add_node(head, 5); add_node(head, 3); add_node(head, 9); add_node(head, 3); printf("Size %d\n", get_size(head)); add_node(head, 7); add_node(head, 1); add_node(head, 4); add_node(head, 9); add_node(head, 13); add_node(head, 2); add_node(head, 0); //delete_min(head, TRUE); temp = add_node(head, 11); temp = add_node(head, 15); temp = find_node(head, 6); if(temp) printf("found %d\n", temp->value); temp = find_node(head, 7); if(temp) printf("found %d\n", temp->value); printf("Size %d\n", get_size(head)); printf("print inorder\n"); print_inorder(head); printf("\n"); printf("print pre_order\n"); print_pre_order(head); printf("\n"); printf("print post_order\n"); print_post_order(head); printf("\n"); printf("height %d\n", get_height(head)); del_node(head, 9); printf("print inorder\n"); print_inorder(head); printf("\n"); bfs(head); return 0; }