Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public int[] computeDepth(int tree[]) {
- int[] depth = new int[tree.length];
- depth[0] = 0;
- for (int index=1; index < tree.length; index++) {
- depth[index] = 1;
- int parentIndex = tree[index];
- while (parentIndex != 0) {
- parentIndex = tree[parentIndex];
- depth[index]++;
- }
- }
- return depth;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement