Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use an IndexTree object to store an index of all the words that are in the provided text, then display the index by performing an

Use an IndexTree object to store an index of all the words that are in the provided text, then display the index by performing an inorder traversal of the tree on java.

Here's the template.

package index;

// Your class. Notice how it has no generics. // This is because we use generics when we have no idea what kind of data we are getting // Here we know we are getting two pieces of data: a string and a line number public class IndexTree {

// This is your root // again, your root does not use generics because you know your nodes // hold strings, an int, and a list of integers private IndexNode root; // Make your constructor // It doesn't need to do anything // complete the methods below // this is your wrapper method // it takes in two pieces of data rather than one // call your recursive add method public void add(String word, int lineNumber){ } // your recursive method for add // Think about how this is slightly different the the regular add method // When you add the word to the index, if it already exists, // you want to add it to the IndexNode that already exists // otherwise make a new indexNode private IndexNode add(IndexNode root, String word, int lineNumber){ return null; } // returns true if the word is in the index public boolean contains(String word){ return false; } // call your recursive method // use book as guide public void delete(String word){ } // your recursive case // remove the word and all the entries for the word // This should be no different than the regular technique. private IndexNode delete(IndexNode root, String word){ return null; } // prints all the words in the index in inorder order // To successfully print it out // this should print out each word followed by the number of occurrences and the list of all occurrences // each word and its data gets its own line public void printIndex(){ } public static void main(String[] args){ IndexTree index = new IndexTree(); // add all the words to the tree // print out the index // test removing a word from the index

} }

package index;

import java.util.List;

public class IndexNode {

// The word for this entry String word; // The number of occurrences for this word int occurences; // A list of line numbers for this word. List list; IndexNode left; IndexNode right; // Constructors // Constructor should take in a word and a line number // it should initialize the list and set occurrences to 1 // Complete This // return the word, the number of occurrences, and the lines it appears on. // string must be one line public String toString(){ return ""; } }

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

Accounting And Auditing Research And Databases Practitioner's Desk Reference

Authors: Thomas R. Weirich, Natalie Tatiana Churyk, Thomas C. Pearson

1st Edition

1118334426, 978-1118334423

More Books

Students also viewed these Databases questions

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago