I am a beginner. I am trying to print an avl tree level by level and it should be from right to left. but the result from left to right. I hope you can solved my problem. Here is the piece of my source code:
void printOrder( TreeNode *treePtr, int *row) {
if(treePtr != NULL){
(*row)++;
printOrder(treePtr->rightPtr,row);
int i;
for(i=0;i<(*row);i--)
printf("\t");
printf("%d\n", treePtr->data);
printOrder(treePtr->leftPtr,row);
(*row)--;
}
}
void printTree( TreeNode *treePtr) {
int row = 0;
printOrder(treePtr,&row);
}
The result:
80
70
50
40
30
The result that i want should be like this:
30\
40\
50
70/
80/