Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int low = 0;
- int high = instances.size()-1;
- while (low < high)
- {
- int mid = (low+high)/2;
- //if i's value is less than mid's value, then high = mid-1
- if(i.priority < instances.get(mid).priority)
- high = mid-1;
- else if(i.priority > instances.get(mid).priority)
- low = mid+1;
- else
- {
- instances.add(mid, i);
- inserted = true;
- low = high;
- }
- }
- if(low >= high && inserted == false)
- instances.add(low, i);
Add Comment
Please, Sign In to add comment