void postorder_call(struct node *root, int *arr, int *index) { if (root == NULL) return; postorder_call(root->left, arr, index); postorder_call(root->right, arr, index); arr[*index] = root->data; ++*(index); }
void postorder(struct node *root, int *arr){ if (root == NULL || arr == NULL){ return; } int ptr = 0; postorder_call(root, arr, &ptr); }
void postorder_call(node * root, int * arr, int * ptr){ /* 1. First Left subtree 2.Next Right subtree 3.Next visit data */ if (root == NULL) return; postorder_call(root->left, arr, ptr); postorder_call(root->right, arr, ptr); arr[*ptr] = root->data; (*ptr)++;//must increament here only to retain value in next function call }
void postorder(struct node *root, int *arr) { if (root == NULL || arr == NULL) return; int index = 0; postorder_call(root, arr, &index); }