void printTreePreOrder(simpul *root, simpul *troot){ if (root!=NULL){ if (root!=troot){ printf("|"); } printf("%s\n", root->nama); printElement(root->bad); printElement(root->good); simpul *node= root->child; if (node != NULL) { if (node->sibling == NULL) {//jika satu anak printTreePreOrder(node, troot); }else{//jika banyak anak while(node->sibling != root->child){ printTreePreOrder(node, troot); node=node->sibling; } //last proses printTreePreOrder(node, troot); } } } }
void printTreePreOrder(node *root) { if (root == NULL) return; printf("%d ",root->data); printTreePreOrder(root->left); printTreePreOrder(root->right); }
void printTreePreOrder(struct TreeNode *p) { if (p != NULL) { printf("%d", p->val); printTreePreOrder(p->left); printTreePreOrder(p->right); } else printf("#"); }
// Function to print binary tree pre order void printTreePreOrder(CNode *t) { if (t != NULL) { printf("%d ", t->iInfo); printTreePreOrder(t->pPrevious); printTreePreOrder(t->pNext); } }
void main() { int array[6] = {10,5,1,7,40,50}; int start = 0; int end = 5; int size = 6; node* root = NULL; root = buldBSTPreOrder(array, size,start,end); printTreePreOrder(root); printf("\n"); }
int main() { struct TreeNode *t = (struct TreeNode *)calloc(4, sizeof(struct TreeNode)); struct TreeNode *p = t; p->val = 1; p->left = ++t; t->val = 2; t->left = t->right = NULL; p->right = ++t; t->val = 3; p->right->left = NULL; p->right->right = ++t; t->val = 4; t->left = t->right = NULL; printTreePreOrder(p); printf("\n"); printf("%d\n", maxDepth(p)); return 0; }
// Main Function, controls program flow int main() { CNode *pHeadC; // For the Doubly linked list CNode *pRoot; // For the binary tree // Initializing doubly linked list pHeadC = (CNode*)malloc(sizeof(CNode)); pHeadC->pNext = NULL; pHeadC->pPrevious = NULL; // Let the user know what we are doing printf("\n\nPlease enter a series of integers.\n"); printf("These will first be stored in a doubly linked list,\n"); printf("then converted into a binary tree.\n"); pHeadC = getNumbers(pHeadC); printf("\nGreat! Before we begin, let's print the doubly linked list: \n"); printDLL(pHeadC); pRoot = convDLLtoBT(pHeadC); printf("\n\nLooks good! Now, let's convert that doubly linked list into a binary tree.\n"); printf("\nFirst, let's print our binary tree in order:\n"); printTree(pRoot); printf("\n\nNow, let's print our binary tree in preorder walk traversal:\n"); printTreePreOrder(pRoot); printf("\n\nNow, let's print our binary tree in postorder walk traversal:\n"); printTreePostOrder(pRoot); freeTreeMem(pRoot); printf("\n\n"); return 0; }
void main() { node* root = NULL; root = insertNode(root,20); root = insertNode(root, 8); root = insertNode(root, 22); root = insertNode(root, 4); root = insertNode(root, 12); root= insertNode(root, 10); root = insertNode(root, 14); printTreePreOrder(root); printf("\n"); node* tmp = NULL; int currentK = 0; int k = 7; tmp = printKSmallest(root, ¤tK, &k); if (tmp!=NULL) { printf("%d \n", tmp->data); } }