Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want binary search in sorted array and after that i want to insert the value accordingly, and i want it in java coding.
Posted
Comments
Richard MacCutchan 22-Aug-11 11:36am    
And which part of this are you having trouble with?
Ashish Tyagi 40 22-Aug-11 11:47am    
ha ha ha, Correct answer(I mean comment).

1 solution

Well just find a proper place to insert new element using binary search and make a place for it by shifting further elements by one position and insert it.

But if you use linked list or map instead of array then insertion, look-up and deletion will be more efficient.

If you are using java collection framework then use :-

SortedSet — a Set that maintains its elements in ascending order.

OR

SortedMap — a Map that maintains its mappings in ascending key order.

Good Luck.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900