Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Order{
- public void genPreOrder(int in[], int startI, int endI, int post[], int startP, int endP){
- if (endP < startP) return;
- System.out.print(post[endP] + " ");
- int i;
- for(i=startI; i<= endI; ++i)
- if(in[i]==post[endP])
- break;
- genPreOrder(in, startI, i-1, post, startP, startP + i - startI - 1);
- genPreOrder(in, i+1, endI, post, startP + i - startI, endP-1);
- }
- public void genPostOrder(int in[], int startI, int endI, int pre[], int startP, int endP){
- if (startI > endI) return;
- int i;
- for(i=startI; i<= endI; i++)
- if(in[i]==pre[startP])
- break;
- genPostOrder(in, startI, i-1, pre, startP + 1, startP + i - startI);
- genPostOrder(in, i+1, endI, pre, startP + i - startI + 1, endI);
- System.out.print(pre[startP] + " ");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement