Advertisement
Guest User

Untitled

a guest
May 28th, 2015
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. class Order{
  2. public void genPreOrder(int in[], int startI, int endI, int post[], int startP, int endP){
  3. if (endP < startP) return;
  4. System.out.print(post[endP] + " ");
  5. int i;
  6. for(i=startI; i<= endI; ++i)
  7. if(in[i]==post[endP])
  8. break;
  9. genPreOrder(in, startI, i-1, post, startP, startP + i - startI - 1);
  10. genPreOrder(in, i+1, endI, post, startP + i - startI, endP-1);
  11. }
  12. public void genPostOrder(int in[], int startI, int endI, int pre[], int startP, int endP){
  13. if (startI > endI) return;
  14. int i;
  15. for(i=startI; i<= endI; i++)
  16. if(in[i]==pre[startP])
  17. break;
  18. genPostOrder(in, startI, i-1, pre, startP + 1, startP + i - startI);
  19. genPostOrder(in, i+1, endI, pre, startP + i - startI + 1, endI);
  20. System.out.print(pre[startP] + " ");
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement