Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java help. Table 2: HuffTree API - Implements Comparable Interface HuffNode API - Implements Comparable Interface - Data & Methods Description HuffTree API: HuffNode root

Java help.

Table 2: HuffTree API - Implements Comparable Interface  
 HuffNode API - Implements Comparable Interface 
<>- 

Data & Methods

Description

HuffTree API:

HuffNode root

Character from the file string.

HuffTree ()

Constructor: default

Set root to null

HuffTree (HuffTree t1,

HuffTree t2)

Constructor:

Initializes root to a new HuffNode with new HuffElement

Adds in t1 as root left subtree

Adds in t2 as root right subtree

Updates roots element to contain a sum of the counts in t1.root element and t2.root element

HuffTree (HuffElement element)

Constructor:

Uses the element to construct a tree with only a root node with the element

HuffNode getRoot()

Returns root.

int compareTo (HuffTree ht)

Compares the root node of this tree to the root node of ht.

HuffNode API:

HuffElement element; 

The node element

public HuffNode left; 

Left child pointer

public HuffNode right; 

Right child pointer

HuffNode (HuffElement elem)

Constructor:

Initializes element to elem

Set left to null

Set right to null

char getChar()

Return the character from the element

int getCount()

Return the character count from the element

void setCount(int count)

Set the count in the element

String getCode()

Return the code from the element

void setCode(String str)

Set the code contained in str in the element

int compareTo (HuffNode node)

Compare this node to node using element.

String toString()

Return string version of the node using the element toString()

public class HuffTree implements Comparable { private HuffNode root;

/** * Create a default binary tree */ public HuffTree() { root = null; }

/** * Create a tree with two subtrees */ public HuffTree (HuffTree t1, HuffTree t2) { // add code }

/** * Create a tree containing a leaf node */ public HuffTree (HuffElement element) { // add code }

/** * Returns the root of the tree */ public HuffNode getRoot() { // add code }

/** * Compare the roots of the HuffTrees */ @Override public int compareTo (HuffTree ht) { // add code }

// Inner class HuffNode whose element is a HuffElement

public static class HuffNode implements Comparable { protected HuffElement element; public HuffNode left; public HuffNode right;

/** * Create a node with passed in element */ public HuffNode (HuffElement elem) { // add code }

/** * Return the element character */ public char getChar() { // add code }

/** * Return the element character count */ public int getCount() { // add code }

/** * Set the element character count */ public void setCount (int count) { // add code }

/** * Return the element character binary code */ public String getCode() { // add code }

/** * Set the element character binary code */ public void setCode (String str) { // add code }

/** * Compare the nodes by comparing the elements */ @Override public int compareTo (HuffNode node) { // add code }

/** * Return node as a String using the element */ @Override public String toString() { // add code } } }

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

Database Processing

Authors: David J. Auer David M. Kroenke

13th Edition

B01366W6DS, 978-0133058352

More Books

Students also viewed these Databases questions

Question

1-4 How will MIS help my career?

Answered: 1 week ago