Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public int getSubHeap(int index,V[] vec){
- if(index>this.size()){
- return -1;
- }
- int i=0;
- LinkedList<Integer> qIndices=new LinkedList<>();
- qIndices.add(index);
- vec[i]=heap.get(index).getValue();
- while(!qIndices.isEmpty()){
- index=qIndices.remove();
- if(hasLeft(index)){
- i=i+1;
- vec[i]=heap.get(left(index)).getValue();
- qIndices.add(left(index));
- }
- if(hasRight(index)){
- i=i+1;
- vec[i]=heap.get(right(index)).getValue();
- qIndices.add(right(index));
- }
- }
- return i+1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement