This project implements a custom Binary Search Tree (BST) and Hash Table in Java, along with supporting classes.
Key features:
- Custom
BSTimplementation with basic operations. - In-order traversal using
iterator(). - Access to both key and value during BST iteration.
- Basic
HashTableimplementation with chaining for collision handling. - Custom key class
MyTestingClasswith a manually tunedhashCode().
Note:
Main.javacurrently tests only the BST functionalities.
src/
├── BST.java
├── Entry.java
├── MyHashTable.java
├── MyTestingClass.java
├── Student.java
├── Main.java
put(K key, V value): Inserts a key-value pair into the BST.get(K key): Retrieves the value associated with a key.delete(K key): Deletes a node by key.size(): Returns the number of nodes.iterator(): In-order traversal, yieldingEntry<K, V>pairs.
Example:
for (var entry : bst) {
System.out.println("Key: " + entry.getKey() + ", Value: " + entry.getValue());
}- Custom hash table with an array of buckets (linked lists).
- Handles collisions with chaining.
- Basic operations:
put,get,remove,contains,size.
(Not tested in the current
Main.java.)
- Custom key class designed for use in hash tables.
- Fields: two integers (
aandb). - Implements a manually tuned
hashCode()andequals()for better uniform distribution.
- Simple class representing a student with
nameandagefields. - Used as values in
MyHashTable.
- Compile all
.javafiles:
javac src/*.java- Run the
Mainclass:
java src.Main- Creates a
BST<Integer, String>. - Inserts several key-value pairs.
- Retrieves a value by key.
- Iterates through the tree using in-order traversal.
- Deletes a key and verifies the result with a second traversal.