In working on a problem to solve Huffman coding, I've developed the following simple code to get a table for values in the binary tree, which prints the path from root to leaf. Forgive what I'm sure is the amateurishness of my code, but I'm hoping that someone could tell me how this code can be changed so as to reverse the output of the recurrent function, ie, print the path from leaf to root. I hope that I've included enough comments to make my code readable.
(I realize that I could just reverse the output as array elements, but I'd prefer to understand how to properly achieve my goal).
At this stage, the output is merely printed to screen, but would be used to write the huffman table.
The code is called with:
Code:
    printPathsRecur(root, 0, rte);
Code:
 //global variables (rte is binary 0 or 1) 
int rte = 0, pathLen = 0;
    int rootpath[16];
Code:
void printPathArray(int rootpath[], int len){
 
   int i;
        //to include tree for single character input
    if (len == 1)
        printf("0");


    else
    {
            // to eliminate extra preceding '0' in array
        for(i=1; i < len; i++)
        {
            printf("%d ",rootpath[i]);
        }
    }
    printf("\n");
}


void printPathsRecur(Tree* root, int pathLen, int rte)
{
    if (root == NULL)
        return;
    // append this node to the path array
    rootpath[pathLen] = rte;
    pathLen++;


        // if it's a leaf, print the path that led to here ( 0's and 1's')
        // and then print the symbol for the path
    if (root->left == NULL && root->right == NULL) 
    {   // pathLen is used for array index for print
        printPathArray(rootpath, pathLen);
        // print alphabetic symbol corresponding to the above path            
        printf("%c\n",root->symbol);
    }
    else
    {
        // otherwise try both subtrees
        printPathsRecur(root->left, pathLen, 0);// '0'? & char path[]
        printPathsRecur(root->right, pathLen, 1);
    }
}