0
所以我试图创建一个基于AVL树和哈希表的智能数据结构。在Java中创建智能数据结构
我在确保我需要首先检查数据类型将根据给定的列表的大小而定。
例如,如果我有一个大小为1000的列表n,它将使用哈希表来实现。对于超过1000的任何内容,使用AVL树。
代码如下:
public class SmartULS<K,V> {
protected TreeMap<K,V> tree = new TreeMap<>();
protected AbstractHashMap<K,V> hashMap = new AbstractHashMap<K,V>();
public void setSmartThresholdULS(size){
int threshold = 1000;
if (size >= threshold) {
map = new AbtractMap<K,V>();
}
else
map = new TreeMap<K,V>();
}
}
现在在这之后,我应该写标准的方法,如
GET(SmartULS,密钥),加(SmartULS,键,值),删除( SmartULS,Key),nextKey(Key),previousKey(Key)等。
我真的失去了如何开始呢?我想过创建这些方法是这样的(写在伪):
Algorithm add(SmartULS, Key, Value):
i<- 0
If SmartULS instanceof AbstractHashMap then
For i to SmartULS.size do
If Key equals to SmartULS[i] then
SmartULS.get(Key).setValue(Value)
Else
SmartULS.add(Key, Value)
Else if SmartULS instanceof TreeMap then
Entry newAdd equals new MapEntry(Key, Value)
Position<Entry> p = treeSearch(root(), Key)
请仔细阅读[问] –
@EngineerDollery而是张贴的,你能不能帮的家伙出来的。 – X1XX