Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. public int getSubHeap(int index,V[] vec){
  2. if(index>this.size()){
  3. return -1;
  4. }
  5.  
  6. int i=0;
  7. LinkedList<Integer> qIndices=new LinkedList<>();
  8. qIndices.add(index);
  9. vec[i]=heap.get(index).getValue();
  10. while(!qIndices.isEmpty()){
  11. index=qIndices.remove();
  12. if(hasLeft(index)){
  13. i=i+1;
  14. vec[i]=heap.get(left(index)).getValue();
  15. qIndices.add(left(index));
  16. }
  17. if(hasRight(index)){
  18. i=i+1;
  19. vec[i]=heap.get(right(index)).getValue();
  20. qIndices.add(right(index));
  21. }
  22. }
  23. return i+1;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement