// Function to print binary tree post order void printTreePostOrder(CNode *t) { if (t != NULL) { printTreePostOrder(t->pPrevious); printTreePostOrder(t->pNext); printf("%d ", t->iInfo); } }
void printTreePostOrder(simpul *root){ if (root!=NULL) { simpul *node= root->child; if (node != NULL) { if (node->sibling == NULL) {//jika satu anak printTreePostOrder(node); }else{//jika banyak anak while(node->sibling != root->child){ printTreePostOrder(node); node=node->sibling; } //last proses printTreePostOrder(node); } } printf("%s\n", root->nama); } }
// 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; }