Find Postorder
int Index(char *low, char *high, char c)
{
    char *tmp = low;
    while (tmp <= high && *tmp != c)
        tmp++;
    if (tmp > high)
        return -1;
    else
        return tmp - low;
}
 
void Find_Post(char *pl, char *ph, char *il, char *ih)
{
    if (pl <= ph && il <= ih) {
        int index = Index(il, ih, *pl);           // *pl is the root
        Find_Post(pl+1, pl+index, il, il+index-1);     // left subtree of *pl
        Find_Post(pl+index+1, ph, il+index+1, ih);    // right subtree of *pl
        printf("%c", *pl);    // print the root last, since we want postorder
    }
}
 
/* Main Function */
int main()
{
    char pre[] = "ABCDEFGH";
    char in[] = "CBEDAGFH";
    Find_Post(pre, pre+7, in, in+7);
    printf("\n");
}

Output:

CEDBGHFA

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License