Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. public int[] computeDepth(int tree[]) {
  2. int[] depth = new int[tree.length];
  3.  
  4. depth[0] = 0;
  5. for (int index=1; index < tree.length; index++) {
  6.  
  7. depth[index] = 1;
  8.  
  9. int parentIndex = tree[index];
  10. while (parentIndex != 0) {
  11.  
  12. parentIndex = tree[parentIndex];
  13. depth[index]++;
  14. }
  15. }
  16.  
  17. return depth;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement