Write a nodups method for the higharray class of the


Programming Projects

To the HighArray class in the highArray.java program (Listing 2.3), add a method called getMax() that returns the value of the highest key in the array, or -1 if the array is empty. Add some code in main() to exercise this method. You can assume all the keys are positive numbers.

Modify the method in Programming Project 2.1 so that the item with the highest key is not only returned by the method, but also removed from the array. Call the method removeMax().

The removeMax() method in Programming Project 2.2 suggests a way to sort the contents of an array by key value. Implement a sorting scheme that does not require modifying the HighArray class, but only the code in main(). You'll need a second array, which will end up inversely sorted. (This scheme is a rather crude variant of the selection sort in Chapter 3, "Simple Sorting.")

Modify the orderedArray.java program (Listing 2.4) so that the insert() and delete() routines, as well as find(), use a binary search, as suggested in the text.

Add a merge() method to the OrdArray class in the orderedArray.java program (Listing 2.4) so that you can merge two ordered source arrays into an ordered destination array. Write code in main() that inserts some random numbers into the two source arrays, invokes merge(), and displays the contents of the resulting destination array. The source arrays may hold different numbers of data items. In your algorithm you will need to compare the keys of the source arrays, picking the smallest one to copy to the destination. You'll also need to handle the situation when one source array exhausts its contents before the other.

Write a noDups() method for the HighArray class of the highArray.java program (Listing 2.3). This method should remove all duplicates from the array. That is, if three items with the key 17 appear in the array, noDups() should remove two of them. Don't worry about maintaining the order of the items. One approach is to first compare every item with all the other items and overwrite any duplicates with a null (or a distinctive value that isn't used for real keys). Then remove all the nulls. Of course, the array size will be reduced.

Attachment:- Java.rar

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Write a nodups method for the higharray class of the
Reference No:- TGS02400011

Now Priced at $20 (50% Discount)

Recommended (99%)

Rated (4.3/5)