Guest User

Untitled

a guest
Jun 20th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. // ...
  2.  
  3. n = a.length + 1;
  4. P = new int[n][n];
  5. W = new int[n][n];
  6. r = new int[n][n];
  7.  
  8. // ...
  9.  
  10. weightedPathLength = P[0][n - 1];
  11.  
  12. root = new Node(r[0][n - 1]);
  13. reconstructTree(0, n - 1, root);
  14. }
  15.  
  16. private void reconstructTree(int i, int j, Node parent) {
  17. int l = r[i][j];
  18. Node child;
  19.  
  20. if (l - i - 1 > 0) {
  21. child = new Node(r[i][l - 1]);
  22. parent.left = child;
  23.  
  24. reconstructTree(i, l - 1, child);
  25. }
  26.  
  27. if (j - l > 0) {
  28. child = new Node(r[l][j]);
  29. parent.right = child;
  30. reconstructTree(l, j, child);
  31. }
  32. }
Add Comment
Please, Sign In to add comment