Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public int getSubHeap(int idx, V[] vet){
- HeapPriorityQuere<K,V> toClone = this.clone();
- List<K> values = new ArrayList<>();
- while(!toClone.isEmpty()){
- values.add(toClone.removemin().getKey());
- }
- //recursive
- List<K> toAdd = new ArrayList<>();
- K first = toAdd.remove(0);
- toAdd.add(first);
- toAdd = Lists.reverse(toAdd);
- if(values.get(idx) != null){
- recursive (toAdd,values,idx);
- }
- for(int i = 0; i< toAdd.size(); i++){
- vet[i] = toAdd.get(i);
- }
- return toAdd.size();
- }
- private void recursive(List<K> toAdd,List<K> values, int idx){
- toAdd.add(values.get(idx))
- if(values.get(2*(idx+1)-1) != null){
- recurisve(toAdd,values,2*(idx+1)-1);
- if(values.get(2*(idx+1) != null){
- recurisve(toAdd,values,2*(idx+1));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement