Question: Need help implementing Huffman Tree class shown below in java import java.util.*; public class HuffmanTree { private class Node { private Node left; private char

Need help implementing Huffman Tree class shown below in java

import java.util.*;

public class HuffmanTree {

private class Node {

private Node left;

private char data;

private Node right;

private Node parent;

private Node(Node L, char d, Node R, Node P) {

left = L;

data = d;

right = R;

parent = P;

}

}

private Node root;

private Node current; // this value is changed by the move methods

public HuffmanTree() {

root = null;

current = null;

}

public HuffmanTree(char d) {

// makes a single node tree

}

public HuffmanTree(String t, char nonLeaf) {

// Assumes t represents a post order representation of the tree as discussed

// nonLeaf is the char value of the data in the non-leaf nodes

// use (char) 128 for the non-leaf value

}

public HuffmanTree(HuffmanTree b1, HuffmanTree b2, char d) {

// makes a new tree where b1 is the left subtree and b2 is the right subtree

// d is the data in the root

}

// use the move methods to traverse the tree

// the move methods change the value of current

public void moveToRoot() {

// change current to reference the root of the tree

}

public void moveToLeft() {

// PRE: the current node is not a leaf

// change current to reference the left child of the current node

}

public void moveToRight() {

// PRE: the current node is not a leaf

// change current to reference the right child of the current node

}

public void moveToParent() {

// PRE: the current node is not the root

// change current to reference the parent of the current node

}

public boolean atRoot() {

// returns true if the current node is the root otherwise returns false

}

public boolean atLeaf() {

// returns true if current references a leaf other wise returns false

}

public char current() {

// returns the data value in the node referenced by current

}

public class PathIterator implements Iterator {

// the iterator returns the path (a series of 0s and 1s) to each leaf

// DO NOT compute all paths in the constructor

// only compute them as needed (similar to what you did in homework 2)

// add private methods and variables as needed

public PathIterator() {

}

public boolean hasNext() {

}

public String next() {

// the format of the string should be leaf value, a space, a sequence of

// 0s and 1s

// the 0s and 1s indicate the path from the root the node containing

// the leaf value

}

public void remove() {

// optional method not implemented

}

}

public Iterator iterator() {

// return a new path iterator object

}

public String toString() {

// returns a string representation of the tree using the postorder format

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!