Question: 3.1: Write a noDups() method for the HighArray class. This method should remove all duplicates from the array. That is, if three items with the

3.1: Write a noDups() method for the HighArray class. 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. Dont worry about maintaining the order of the items. Of course, the array size will be reduced. Finally, in the answer section of your lab report, please analyze the time complexity of your method.

3.2: Write a isSorted() method for the HighArray class. This method should check if the array is sorted or not. if the array is sorted in ascending order, return 1; If the array is sorted in descending order, return -1; For all other situations (such as array is not sorted, array is empty, array has only 1 item, or all items in the array are equal), return 0. Finally, in the answer section of your lab report, please analyze the time complexity of your method.

All questions can be solved in one project within one java file. Please add some code in main() function to exercise all those methods you added or revised.

Code:

class HighArray { private long[] a; // ref to array a private int nElems; // number of data items //----------------------------------------------------------- public HighArray(int max) // constructor { a = new long[max]; // create the array nElems = 0; // no items yet } //----------------------------------------------------------- public boolean find(long searchKey) { // find specified value int j; for(j=0; j

arr.insert(77); // insert 10 items arr.insert(99); arr.insert(44); arr.insert(55); arr.insert(22); arr.insert(88); arr.insert(11); arr.insert(00); arr.insert(66); arr.insert(33);

arr.display(); // display items

int searchKey = 35; // search for item if( arr.find(searchKey) ) System.out.println("Found " + searchKey); else System.out.println("Can't find " + searchKey);

arr.delete(00); // delete 3 items arr.delete(55); arr.delete(99);

arr.display(); // display items again } // end main() } // end class HighArrayApp

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!