how to sort data at the time of adding it, not later?

后端 未结 4 1932
醉话见心
醉话见心 2021-01-21 18:29

I am new to algorithms so please forgive me if this sounds basic or stupid.

I want to know this : instead of adding data into some kind of list and then performing a sor

4条回答
  •  野性不改
    2021-01-21 19:08

    You want to maintain a sorted array at all times, so you shall find a correct place in sequence for every new element you want to add to the array. This can be done efficiently (O(logn) complexity) by utilizing a modified binary search algorithm.

提交回复
热议问题