Inserting a number into a sorted array!

Posted by Jay on Stack Overflow See other posts from Stack Overflow or by Jay
Published on 2010-06-07T12:09:59Z Indexed on 2010/06/07 12:12 UTC
Read the original article Hit count: 179

Filed under:
|

I would like to write a piece of code for inserting a number into a sorted array at the appropriate position (i.e. the array should still remain sorted after insertion)

My data structure doesn't allow duplicates.

I am planning to do something like this: 1. Find the right index where I should be putting this element using binary search 2. Create space for this element, by moving all the elements from that index down. 3. Put this element there.

Is there any other better way?

© Stack Overflow or respective owner

Related posts about c

    Related posts about data-structures