Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. public void insert(int keyVal, StringListExt listVal){
  2. ArrayHeapEntry newEntry = new ArrayHeapEntry(keyVal, listVal);
  3. heap.add(newEntry);
  4.  
  5. int index = heap.size() - 1;
  6. int child = index;
  7. int parent = (child - 1) / 2;
  8.  
  9. if (heap.size()-1 != 0){
  10. while (heap.get(parent).getKey() < heap.get(child).getKey()) {
  11. ArrayHeapEntry temp = heap.get(child);
  12. heap.set(heap.indexOf(heap.get(child)), heap.get(parent));
  13. heap.set(heap.indexOf(heap.get(parent)), temp);
  14. child = parent;
  15. parent = (child - 1) / 2;
  16. }
  17. }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement