Question: Java Programming Implement the ADT dictionary by using a binary search tree . Use the ADT dictionary in a word count program. Your class WordCount
Java Programming
Implement the ADT dictionary by using a binary search tree. Use the ADT dictionary in a word count program. Your class WordCount will take an input from command line for the name of a text file. This text file will contain words or numbers that are tokenized (separated by whitespace). Finish the implementation of BSTDictionary and create the WordCount program. The text file and source code is below. If there is extraneous methods from the interfaces just make the implementation throw operationnotsupportedexception.
public class BinaryNode
public BinaryNode
public void setRightChild(BinaryNode
BinaryTree.java
import java.util.Iterator; import java.util.Stack;
public class BinaryTree
private BinaryNode
public BinaryTree() { root = null; }
public BinaryTree(T rootData) { root = new BinaryNode
public BinaryTree(T rootData, BinaryTree
public void setTree(T rootData) { root = new BinaryNode
public void setTree(T rootData, BinaryTree
private void privateSetTree(T rootData, BinaryTree
if ((left != null) && (!left.isEmpty())) { root.setLeftChild(left.root.copy()); } if ((right != null) && (!right.isEmpty())) { root.setRightChild(right.root.copy()); } }
public T getRootData() { return root.getData(); }
public int getHeight() { return root.getHeight(); }
public int getNumberOfNodes() { return root.getNumberOfNodes(); }
public boolean isEmpty() { return root == null; }
public void clear() { root = null; }
protected BinaryNode
public Iterator
public Iterator
public Iterator
public Iterator
private class PostorderIterator implements Iterator
private Stack
public PostorderIterator() { nodeStack = new Stack<>(); current = root; populateStack(current); } private void populateStack(BinaryNode
public boolean hasNext() { return !nodeStack.isEmpty(); }
public T next() { return nodeStack.pop().getData(); }
}
}
BinaryTreeInterface.java
public interface BinaryTreeInterface
TreeIteratorInterface.java
import java.util.Iterator;
public interface TreeIteratorInterface
DictionaryInterface.java
import java.util.Iterator;
public interface DictionaryInterface
public V add(K key, V value);
public V remove(K key);
public V getValue(K key);
public boolean contains(K key);
public Iterator
public boolean isEmpty();
public int getSize();
public void clear();
}
BSTDictionary.java
import java.util.Iterator;
public class BSTDictionary
implements DictionaryInterface
private SearchTreeInterface
public BSTDictionary(){
bst = new BinarySearchTree<>();
}
private class Entry,T>
implements Comparable
{
private S key;
private T value;
private Entry(S searchKey, T dataValue){
key = searchKey;
value = dataValue;
}
public int compareTo(Entry other){
return key.compareTo(other.key);
}
// Entry should also define the method equals, to String, getKey, getValue, and setValue. no setKey is provided
}
@Override
public V add(K key, V value) {
// TODO Auto-generated method stub
return null;
}
@Override
public V remove(K key) {
// TODO Auto-generated method stub
return null;
}
@Override
public V getValue(K key) {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean contains(K key) {
// TODO Auto-generated method stub
return false;
}
@Override
public Iterator
// TODO Auto-generated method stub
return null;
}
@Override
public boolean isEmpty() {
// TODO Auto-generated method stub
return false;
}
@Override
public int getSize() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void clear() {
// TODO Auto-generated method stub
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
