Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a generic class that implements the interface with the methods directions given: --------------------------------------------------------------------------------------------------------- import java.util.ArrayList; /** * This is a generic LinkedConverterTreeInterface * *

Create a generic class that implements the interface with the methods directions given:

---------------------------------------------------------------------------------------------------------

import java.util.ArrayList; /** * This is a generic LinkedConverterTreeInterface * * It is intended for creation of LinkedTrees that do conversion * using a LinkedTree * * Note: usually addNode, fetchNode and LNROutputTraversal would be private * * * */ public interface LinkedConverterTreeInterface { /** * Returns a reference to the root * @return reference to root */ public TreeNode getRoot(); /** * sets the root of the Tree * @param newNode a TreeNode that will be the new root */ public void setRoot(TreeNode newNode); /** * Adds result to the correct position in the tree based on the code * This method will call the recursive method addNode * * @param code the code for the new node to be added * @return the linkedConverterTree with the new node added */ public LinkedConverterTreeInterface insert(T code, T result); /** * This is a recursive method that adds element to the correct position * in the tree based on the code. * * @param root the root of the tree for this particular recursive instance of addNode * @param code the code for this particular recursive instance of addNode * @param letter the data of the new TreeNode to be added */ public void addNode(TreeNode root, T code, T letter); /** * Fetch the data in the tree based on the code * This method will call the recursive method fetchNode * * @param code the code that describes the traversals within the tree * @return the result that corresponds to the code */ public T fetch(String code); /** * This is the recursive method that fetches the data of the TreeNode * that corresponds with the code * * @param root the root of the tree for this particular recursive instance of addNode * @param code the code for this particular recursive instance of fetchNode * @return the data corresponding to the code */ public T fetchNode(TreeNode root, T code); /** * This operation is not supported for a LinkedConverterTree * @param data data of node to be deleted * @return reference to the current tree * @throws UnsupportedOperationException */ public LinkedConverterTreeInterface delete(T data) throws UnsupportedOperationException; /** * This operation is not supported for a LinkedConverterTree * @return reference to the current tree * @throws UnsupportedOperationException */ public LinkedConverterTreeInterface update() throws UnsupportedOperationException; /** * This method builds the LinkedConverterTree by inserting TreeNodes * into their proper locations * */ public void buildTree(); /** * Returns an ArrayList of the items in the linked converter Tree in LNR (Inorder) Traversal order * Used for testing to make sure tree is built correctly * @return an ArrayList of the items in the linked Tree */ public ArrayList toArrayList(); /** * The recursive method to put the contents of the linked converter tree in an ArrayList * LNR (Inorder) * @param root the root of the tree for this particular recursive instance * @param list the ArrayList that will hold the contents of the tree in LNR order */ public void LNRoutputTraversal(TreeNode root, ArrayList list); } 

-------------------------------------------------------------------------------------------------------------------------------

interface LinkedConverterTreeInterface

All Known Implementing Classes:

MorseCodeTree

public interface LinkedConverterTreeInterface 

This is a generic LinkedConverterTreeInterface It is intended for creation of LinkedTrees that do conversion using a LinkedTree Note: usually addNode, fetchNode and LNROutputTraversal would be private

Method Summary
void addNode(TreeNode root, T code, T letter) This is a recursive method that adds element to the correct position in the tree based on the code.
void buildTree() This method builds the LinkedConverterTree by inserting TreeNodes into their proper locations
LinkedConverterTreeInterface delete(T data) This operation is not supported for a LinkedConverterTree
T fetch(java.lang.String code) Fetch the data in the tree based on the code This method will call the recursive method fetchNode
T fetchNode(TreeNode root, T code) This is the recursive method that fetches the data of the TreeNode that corresponds with the code
TreeNode getRoot() Returns a reference to the root
LinkedConverterTreeInterface insert(T code, T result) Adds result to the correct position in the tree based on the code This method will call the recursive method addNode
void LNRoutputTraversal(TreeNode root, java.util.ArrayList list) The recursive method to put the contents of the linked converter tree in an ArrayList LNR (Inorder)
void setRoot(TreeNode newNode) sets the root of the Tree
java.util.ArrayList toArrayList() Returns an ArrayList of the items in the linked converter Tree in LNR (Inorder) Traversal order Used for testing to make sure tree is built correctly
LinkedConverterTreeInterface update() This operation is not supported for a LinkedConverterTree
Method Detail

getRoot

TreeNode getRoot() 

Returns a reference to the root

Returns:

reference to root

setRoot

void setRoot(TreeNode newNode) 

sets the root of the Tree

Parameters:

newNode - a TreeNode that will be the new root

insert

LinkedConverterTreeInterface insert(T code, T result) 

Adds result to the correct position in the tree based on the code This method will call the recursive method addNode

Parameters:

code - the code for the new node to be added

Returns:

the linkedConverterTree with the new node added

addNode

void addNode(TreeNode root, T code, T letter) 

This is a recursive method that adds element to the correct position in the tree based on the code.

Parameters:

root - the root of the tree for this particular recursive instance of addNode

code - the code for this particular recursive instance of addNode

letter - the data of the new TreeNode to be added

fetch

T fetch(java.lang.String code) 

Fetch the data in the tree based on the code This method will call the recursive method fetchNode

Parameters:

code - the code that describes the traversals within the tree

Returns:

the result that corresponds to the code

fetchNode

T fetchNode(TreeNode root, T code) 

This is the recursive method that fetches the data of the TreeNode that corresponds with the code

Parameters:

root - the root of the tree for this particular recursive instance of addNode

code - the code for this particular recursive instance of fetchNode

Returns:

the data corresponding to the code

delete

LinkedConverterTreeInterface delete(T data) throws java.lang.UnsupportedOperationException 

This operation is not supported for a LinkedConverterTree

Parameters:

data - data of node to be deleted

Returns:

reference to the current tree

Throws:

java.lang.UnsupportedOperationException

update

LinkedConverterTreeInterface update() throws java.lang.UnsupportedOperationException 

This operation is not supported for a LinkedConverterTree

Returns:

reference to the current tree

Throws:

java.lang.UnsupportedOperationException

buildTree

void buildTree() 

This method builds the LinkedConverterTree by inserting TreeNodes into their proper locations

toArrayList

java.util.ArrayList toArrayList() 

Returns an ArrayList of the items in the linked converter Tree in LNR (Inorder) Traversal order Used for testing to make sure tree is built correctly

Returns:

an ArrayList of the items in the linked Tree

LNRoutputTraversal

void LNRoutputTraversal(TreeNode root, java.util.ArrayList list) 

The recursive method to put the contents of the linked converter tree in an ArrayList LNR (Inorder)

Parameters:

root - the root of the tree for this particular recursive instance

list - the ArrayList that will hold the contents of the tree in LNR order

-----------------------------------------------------------------------------------

 

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

Intelligent Information And Database Systems 6th Asian Conference Aciids 2014 Bangkok Thailand April 7 9 2014 Proceedings Part I 9 2014 Proceedings Part 1 Lnai 8397

Authors: Ngoc-Thanh Nguyen ,Boonwat Attachoo ,Bogdan Trawinski ,Kulwadee Somboonviwat

2014th Edition

3319054759, 978-3319054759

Students also viewed these Databases questions

Question

Address an envelope properly.

Answered: 1 week ago