I was able to implement Hashtable using array by simply using the following data structure.
LinkedList<Item<K,V>> table[]
const int MAX_SIZE = 100
i.e an array of linked list(hashing with chaining).
Now in various books,they say we can implement a hashtable with a BST if we want ordered data. How do I incorporate both key and value in a BST. Although I can store both just as I store a single item of data, but the key gives an integer that acts like an index to the array after it has been to a hash function. How do I use the key in BST? I don't need any index?
What I can think of is that I can compare two keys using the function and then do normal insertion,deletion accordingly.
EDITS:
Suppose I have BST from scratch
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)
}
How do I use the key mapped to integer to implement the
insert(V value)
in BST.