Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.75 KB | None | 0 0
  1. public int getSubHeap(int idx, V[] vet){
  2.     HeapPriorityQuere<K,V> toClone = this.clone();
  3.     List<K> values = new ArrayList<>();
  4.     while(!toClone.isEmpty()){
  5.         values.add(toClone.removemin().getKey());
  6.     }
  7.     //recursive
  8.     List<K> toAdd = new ArrayList<>();
  9.     K first = toAdd.remove(0);
  10.     toAdd.add(first);
  11.     toAdd = Lists.reverse(toAdd);
  12.     if(values.get(idx) != null){
  13.         recursive (toAdd,values,idx);
  14.     }
  15.     for(int i = 0; i< toAdd.size(); i++){
  16.         vet[i] = toAdd.get(i);
  17.     }
  18.     return toAdd.size();
  19. }
  20.  
  21. private void recursive(List<K> toAdd,List<K> values, int idx){
  22.     toAdd.add(values.get(idx))
  23.     if(values.get(2*(idx+1)-1) != null){
  24.         recurisve(toAdd,values,2*(idx+1)-1);
  25.         if(values.get(2*(idx+1) != null){
  26.             recurisve(toAdd,values,2*(idx+1));
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement