Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

AWS Certified Database Study Guide Specialty DBS-C01 Exam

Authors: Matheus Arrais, Rene Martinez Bravet, Leonardo Ciccone, Angie Nobre Cocharero, Erika Kurauchi, Hugo Rozestraten

1st Edition

1119778956, 978-1119778950

More Books

Students also viewed these Databases questions

Question

2. What process will you put in place to address conflicts?

Answered: 1 week ago