【发布时间】:2013-06-24 15:56:55
【问题描述】:
通过简单地使用以下数据结构,我能够使用数组实现 Hashtable。
LinkedList<Item<K,V>> table[]
const int MAX_SIZE = 100
即链表数组(链式散列)。
现在在各种书籍中,他们说如果我们想要有序数据,我们可以使用 BST 实现哈希表。 如何将键和值合并到 BST 中。虽然我可以像存储单个数据项一样存储两者,但是键提供了一个整数,在它已经到哈希函数之后,它就像数组的索引一样。如何在 BST 中使用密钥?我不需要任何索引?
我能想到的是,我可以使用该功能比较两个键,然后进行正常的插入,相应的删除。
编辑:
假设我从头开始拥有 BST
class Node {
K key;
V value;
Node left;
Node right;
}
class BinarySearchTree {
Node root;
}
class Hashtable {
BinarySearchTree bst;
public void Hashtable() {
bst = new BinarySearchTree();
}
//hashfunction(K key)
//get(K Key)
//put(K key,V value)
//remove(K key)
}
如何使用映射到整数的键来实现
insert(V value)
在英国夏令时。
【问题讨论】:
-
我对编程很陌生,但你不能用树形图代替吗? stackoverflow.com/questions/13373854/…
标签: java hashtable binary-search-tree