void Tree_Destroy(Node * h) { if (h == NULL) return; Tree_Destroy(h -> lc); Tree_Destroy(h -> rc); free(h); }
int main() { Node* root = Tree_GetRoot(8); Tree_InsertNode(root, 9); Tree_InsertNode(root, 18); Tree_InsertNode(root, 5); Tree_InsertNode(root, 2); Tree_InsertNode(root, 7); Tree_InsertNode(root, 12); Tree_InsertNode(root, 23); Tree_InsertNode(root, 21); printf("Node Count: %d\n", Tree_Size); Tree_Destroy(root); return 0; }
int main (int argc, char * * argv) { if (argc != 3) { printf("\nInvalid number of arguments\n"); return EXIT_FAILURE; } char * in_file = argv[1]; char * out_file = argv[2]; // arr is an array implementation of a binary tree // the root node is the node of index num_n Node * head = Load_File(in_file); clock_t pack_t = clock(); Find_Area(head); double x_new = 0; double y_prev = head -> height; Find_Coords(head, &x_new, &y_prev); pack_t = clock() - pack_t; double x = -1; double y = -1; printf("\nPreorder: \n"); Preorder(head); printf("\n\nInorder: \n"); Inorder(head); printf("\n\nPostorder: \n"); Postorder(head, &x, &y); printf("\n\nWidth: %le\nHeight: %le\n", head -> width, head -> height); printf("\nX-coordinate: %le\nY-coordinate:%le\n", x, y); printf("\nElapsed Time: %le\n\n", ((double) pack_t) / CLOCKS_PER_SEC); FILE * f = fopen(out_file, "w"); Save_File(f, head); fclose(f); Tree_Destroy(head); return EXIT_SUCCESS; }