Guest User

Untitled

a guest
Jun 18th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1.  
  2. int low = 0;
  3. int high = instances.size()-1;
  4. while (low < high)
  5. {
  6. int mid = (low+high)/2;
  7. //if i's value is less than mid's value, then high = mid-1
  8. if(i.priority < instances.get(mid).priority)
  9. high = mid-1;
  10. else if(i.priority > instances.get(mid).priority)
  11. low = mid+1;
  12. else
  13. {
  14. instances.add(mid, i);
  15. inserted = true;
  16. low = high;
  17. }
  18. }
  19. if(low >= high && inserted == false)
  20. instances.add(low, i);
Add Comment
Please, Sign In to add comment