void postNext(struct node *root, int *arr, int *index) { if (root->left != NULL) postNext(root->left, arr, index); if (root->right != NULL) postNext(root->right, arr, index); arr[(*index)++] = root->data; }
void postorder(struct node *root, int *arr){ if (root == NULL || arr == NULL) return; else { int index = 0; postNext(root, arr, &index); } }
ListNode *mergeKLists(vector<ListNode *> &lists) { int k = (int) lists.size(); if (k == 0){ return NULL; } ListNode **minEle = min_element(&lists[0], &lists[k], comp); if (*minEle == NULL){ return NULL; } ListNode *head = postNext(*minEle); head->next = mergeKLists(lists); return head; }
void BtreeNode::for_postIter(const std::function<void(const BtreeNode *)> &fn)const { for(const BtreeNode *x = postFirst(); x; x=postNext()) fn(x); }