Question
Write a java cross-reference program implemented with hashing so that the program outputs alphabetized list of all words in an input file along with line
Write a java cross-reference program implemented with hashing so that the program outputs alphabetized list of all words in an input file along with line numbers on which the words occur.
For each input word the program determines its home position with a hash function implemented in the program. Collision resolution should be implemented with the linear probing technique. If the home position is free, an object is put there that includes this word and a one-node linked list with the line number of the line on which the word was encountered. If the position is occupied by an object that already includes this word, add the line number to the list of line numbers in this object. If the home position is occupied by an object for another word, use linear probing to find a free cell if the word has been encountered for the first time or a cell with an object that already includes this word. During linear probing, start from the beginning of the hash table when its end has been reached. When all positions in the table are occupied, print a message and continue processing the file.
To sort the data in the hash table, count how many non-null entries in this table you have, create a new array of the size equal to the count, copy all entries from the hash table to the new array and sort this new array with
Arrays.sort(a); // see p. 19 of the textbook;
and then display it with
System.out.print(Arrays.toString(a)); // same page; and
ction 1.2 oBIECT ORIENTED PROGRAMMING IN JAVA 19 Arrays are passed to reference; that is, changes performed in a method that takes an array methods by For example, if a for doubling parameter affects the array permanently. values in integer arrays is define public void doubleArray (inti a) for (int i 0; i a. length it a [i] a [i] then the following code al 1 al [21 13 double Array(al) System out.print (Arrays. tostring (al) results in printing numbers 24, 26, and 26 In Java 1.2, the class Arrays is added with several useful methods to be applied to arrays, in particular binarysearch equals fill and sort In ava 5, method hashCode(), deepHashCode(), deepEquals tostring deepTostring have been added, and in Java 6, the Arrays class has been amplified with methods copy of and copyo For example, to sort an array, it is enough to import class java.util.Arrays and execute one of the ver sions of the method sort, for example, Arrays sort (a)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started