void printPostorder(node *root){ if(root != 0){ printPostorder(root->left); printPostorder(root->right); printf("%d\n", root->key); } }
void printPostorder(struct node* node) { if (node == NULL) return; printPostorder(node->left); printPostorder(node->right); std::cout << node->data << " "; }
// Given a binary tree, print out the nodes of the tree // according to a bottom-up "postorder" traversel -- both // subtrees of a node are printed out completely before the node // itself is printed, and each left subtree is printed before the right void printPostorder(struct node* node) { if (!node) return; else { printPostorder(node->left); printPostorder(node->right); printf("%d ", node->data); } }
void BinarySearchTree::printPostorder(Node *node) { if (node == NULL) { return; } printPostorder(node->left); printPostorder(node->right); print(node); }
void printPostorder(struct node* root) { if(root!=NULL){ printPostorder(root->left); printPostorder(root->right); printf("%d ",root->data); } }
/* Given a non-empty binary search tree(ordered) iterate over the nodes to print them in postorder */ void printPostorder(struct node* root) { if(root->left == 0) printf("%d\n",root->data); else { printPostorder(root->left); printPostorder(root->right); printf("%d\n",root->data); } }
void printPostorder (struct node* node) { if (node == NULL) { return; } printPostorder(node->left); printPostorder(node->right); printf("%d ", node->data); }
void printPostorder(node *n) { if(n == NULL) return; else { printPostorder(n -> left); printPostorder(n -> right); printf("%d ", n -> data); } }
/* print the tree postorder */ void printPostorder(struct avl_node *node) { if (node == NULL) return; /* process the left node */ printPostorder(node->left); /* process the right node */ printPostorder(node->right); /* process the root */ printf("%d ", node->key); }
void printPostorder(node * tree) { if (tree == NULL) return; printPostorder(TLEFT); printPostorder(TRIGHT); if (tree->split=='-') printf("(%le,%le)",tree->width,tree->height); else printf(("%c"),tree->split); //printf("Index = %d, width = %f, height = %f, split = %c, xcoord = %f, ycoord = %f, parNode = %d\n", tree->index, tree->width, tree->height, tree->split, tree->xcoord, tree->ycoord, tree->parNode); }
/* post order traversal of binary tree */ void printPostorder(struct binaryTreeNode *node) { if (node == NULL) return; //first recur on left subtree printPostorder(node->left); //then recur on right subtree printPostorder(node->right); // deal with the node printf("%d ", node->data); }
int main() { int count = 0; int size = 0; int i; scanf("%d", &count); for(i = 0; i < count; i++) { scanf("%d ", &size); preIndex = 0; char *in, *pre; in = malloc(size*sizeof(char)); pre = malloc(size*sizeof(char)); scanf("%s %s", pre, in); Node *root = malloc(sizeof(Node)); root = build(in, pre, 0, size - 1); printf("Teste %d: ", i); printPostorder(root); printf("\n"); } return 0; }
int main(int argc, char **argv) { //Checking error if (argc < 2) { printf("usage: %s <input_filename>\n", argv[0]); return 0; } //Open file FILE *in = fopen(argv[1], "r"); if (in == NULL) return 0; //Declaration of variable int i, size,level; //Scanning size from file fscanf(in, "%d", &size); //allocating memory for array int *array = malloc(size * sizeof(int)); //Scanning number from the file for (i=0; i<size; i++) fscanf(in, "%d", &array[i]); //Declaring a node bst *root =NULL; //Creating BST root=createBST(array,size); //print in-order,pre-order,post-order tree traversal printf("Creating Binary Search Tree...\n"); printf("In-order traversal: "); printInorder(root); printf("\n"); printf("Pre-order traversal: "); printPreorder(root); printf("\n"); printf("Post-order traversal: "); printPostorder(root); printf("\n"); //Sort arrat sort(array,size); //Creatin binary tree with minimum level root=createMinBST(array,0,size-1); //printing BST printf("Minimum Height BST\n"); printTree(root); //Bonus printf("Bonus.Please enter level of the tree:"); scanf("%d",&level); if(level>height(root)) printf("\nThe maximum height of this tree is %d",height(root)); else printGivenLevel(root,level); return 0; }
int main(int argc, char *argv[]){ //check command line arguments if(argc != 2){ printf("usage: ./a.out <input_filename>"); exit(0); } //open the file FILE* input = fopen(argv[1],"r"); if(input == NULL){ printf("File not found"); exit(0); } bst* root = NULL; int i = 0; int size = 0; fscanf(input,"%d",&size); int *a = (int *)malloc(sizeof(int)*size);//create the array for(i=0;i<size;i++){ fscanf(input,"%d",&a[i]); } close(input); //close file //printout the different ways printf("Creating Binary Search Tree\n"); root = createBST(a,size); printf("In-Order traversal: "); printInorder(root); printf("\nPre-Order traversal: "); printPreorder(root); printf("\nPost-Order traversal: "); printPostorder(root); printf("\n\nMinimum Height BST\n"); sort(a,size); root = createMinBST(a,0,size-1); printTree(root); free(a); //free mem return 0; }
int main(int argc, char **argv) { if(argc < 2) { printf("usage: %s <input_filename>/n", argv[0]); return; } FILE* input = fopen(argv[1], "r"); if (input == NULL) return; int i, size; fscanf(input, "%d", &size); int array[size]; for(i=0; i<size; i++) fscanf(input, "%d", &array[i]); //Creates Binary Tree printf("Creating Binary Tree...\n"); bst* root = createBST(array, size); //Printing Inorder Traversal printf("Inorder Traversal: "); printInorder(root); printf("\n"); //Printing Pre-order Traversal printf("Pre-Order Traversal: "); printPreorder(root); printf("\n"); //Printing Postorder Traversal printf("Postorder Traversal: "); printPostorder(root); printf("\n"); //Printing the Binary Tree printf("\nMinimum Height BST\n"); sort(array, size); root = createMinBST(array, array[0], array[size-1]); printTree(root); fclose(input); free(root); return 0; }
int main() { node *root = NULL, *rootb = NULL, *rooth = NULL, *temp; int sum = 25, *a, l = 0; a = (int *)malloc(sizeof(int)); root = insert(root, 10); root = insert(root, 7); root = insert(root, 6); root = insert(root, 8); root = insert(root, 13); root = insert(root, 15); root = insert(root, 11); printf("Part2: Size: \t%d\n", size(root, 0)); printf("Part3: Depth: \t%d\n", maxDepth(root)); printf("Part4: Min: \t%d\n", minValue(root)); printf("Part5: Post: \t");printPostorder(root);printf("\n"); printf("Part6: Path Sum: %d %s\n", sum, hasPathSum(root, sum)?"True":"False"); printf("Part7: Leaf Paths");printPaths(root, a, l); printf("\n"); inorder(root);printf("\n"); printf("Part8: Mirror: ");mirror(root);inorder(root);printf("\n"); rootb = insert(rootb, 10); rootb = insert(rootb, 7); rootb = insert(rootb, 6); rootb = insert(rootb, 8); rootb = insert(rootb, 13); rootb = insert(rootb, 15); rootb = insert(rootb, 11); printf("Part9: doubleTree: ");doubleTree(rootb);inorder(rootb);printf("\n"); printf("Part10: sameTree: %s\n", sameTree(root, root)?"True":"False"); mirror(root); printf("Part11: isBST: %s\n", isBST(root)?"True":"False"); printf("Part12: Tree list: "); rooth = treeList(root); temp = rooth -> left; printf("%d ", rooth -> data); while(temp != rooth) { printf("%d ", temp -> data); temp = temp -> left; } printf("\n"); return(0); }
int main(int argc, char** argv){ node *root = NULL; insert(5, &root); insert(10, &root); insert(8, &root); insert(3, &root); insert(4, &root); printPreorder(root); printInorder(root); printPostorder(root); printf("%d was found\n", (search(8, root)->key)); destroyTree(root); }
int main() { node *root; node *tmp; //int i; root = NULL; //insert nodes insert(&root, 9); insert(&root, 4); insert(&root, 15); insert(&root, 6); insert(&root, 12); insert(&root, 17); insert(&root, 2); //Printing nodes of tree printf("Pre Order Display\n"); printPreorder(root); printf("In Order Display\n"); printInorder(root); printf("Post Order Display\n"); printPostorder(root); // Search node into tree tmp = searchTree(&root, 4); if (tmp) { printf("Searched node=%d\n", tmp->data); } else { printf("Data Not found in tree.\n"); } //Deleting all nodes of tree deleteTree(root); return 0; }
/* Driver program to test above functions*/ int main() { struct node *root = newNode(1); root->left = newNode(2); root->right = newNode(3); root->left->left = newNode(4); root->left->right = newNode(5); printf("\nPreorder traversal of binary tree is \n"); printPreorder(root); printf("\nInorder traversal of binary tree is \n"); printInorder(root); printf("\nPostorder traversal of binary tree is \n"); printPostorder(root); getchar(); return 0; }
int main() { struct node *root = NULL; root = insert(root, 4); root = insert(root, 2); root = insert(root, 3); root = insert(root, 1); root = insert(root, 5); root = mirror(root); std::cout << sameTree(root, root) << std::endl; std::cout << size(root) << std::endl; std::cout << maxDepth(root) << std::endl; printInoder(root); std::cout << std::endl; printPostorder(root); std::cout << std::endl; printPreorder(root); return 0; }
int main() { struct node* root = NewNode(4); insert(root, 2); insert(root, 5); insert(root, 1); insert(root, 3); printf("size of tree: %d\n", size(root)); printf("maxDepth of tree: %d\n", maxDepth(root)); printf("minValue of tree: %d\n", minValue(root)); printTree(root); printf("\n"); printPostorder(root); printf("\n"); if (hasPathSum(root, 9)) printf("Tree has a root-to-leaf path that sums to 9\n"); printPaths(root); return 0; }
main() { struct node* root=BuildTree(); printPostorder(root); }
int main(int argc, char * * argv) { if (argc != 3) { printf("usage: ./proj4 input output\n"); return EXIT_FAILURE; } int index = 0; double x = 0, y=0; // Build binary tree stack * root = loadFile(argv[1], &index); node * head = nodeCreate(root->stackNode->width, root->stackNode->height, root->stackNode->split, root->stackNode->index-1); //= buildTree(root); root = StackPop(root); buildTree(root, head, &head, index); node * tree = NULL; tree = nodeArrange(tree, &head); // Packing clock_t timeStart = clock(); assignCutline(tree); setCoord(tree); clock_t timeEnd = clock(); double packTime = (double) (timeEnd - timeStart) / CLOCKS_PER_SEC; searchNode(tree, &x, &y, 1); //printPostorderFull(tree); //Reset output file and save output FILE * fptr = fopen(argv[2], "w"); saveTree(tree, argv[2]); // Screen dump printf("Preorder: "); printPreorder(tree); printf("\n\nInorder: "); printInorder(tree); printf("\n\nPostorder: "); printPostorder(tree); printf("\n\nWidth: %le", tree->width); printf("\nHeight: %le", tree->height); printf("\n\nX-coordinate: %le", x); printf("\nY-coordinate: %le", y); printf("\n"); // Rerooting box * minBox = malloc(sizeof(box)); minBox->width = tree->width; minBox->height = tree->height; timeStart = clock(); // ------------------------------------ to run cases without rerooting, comment out the following lines while (tree->right->split!='-') { tree = reroot(tree, minBox); decideMin(minBox, tree); //printPostorderFull(tree); } // ------------------------------------ timeEnd = clock(); double rootTime = (double) (timeEnd - timeStart) / CLOCKS_PER_SEC; printf("\nElapsed Time: %le", packTime); printf("\n\nBest width: %le", minBox->width); printf("\nBest height: %le\n", minBox->height); printf("\nElapsed Time for re-routing: %le\n", rootTime); // Free stack while(root!=NULL){ root = StackPop(root); } // Memory management free(root); free(minBox); deleteTree(head); deleteTree(tree); fclose(fptr); return EXIT_SUCCESS; }
void BinarySearchTree::printPostorder() const { print("Post-order : "); printPostorder(root); println(); }
int main(int argc, char* argv[]) { struct node* root = buildBSTree(); printPostorder(root); }