二元搜索和插入 [英] binary serach along with insertion

查看:88
本文介绍了二元搜索和插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在排序后的数组中进行二进制搜索,然后我要相应地插入值,并希望在Java编码中使用它.

i want binary search in sorted array and after that i want to insert the value accordingly, and i want it in java coding.

推荐答案

好吧,找到一个使用二进制搜索插入新元素的适当位置,并通过将其他元素移动一个位置并插入来为其放置位置.

但是,如果使用链接列表或映射而不是数组,则插入,查找和删除将更加有效.

如果您使用的是Java收集框架,请使用:-

SortedSet —一个按其升序维护其元素的Set.



SortedMap —一个以键升序维护其映射的Map.

祝你好运.
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.


这篇关于二元搜索和插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆