Question: Java programming. 3.2 Add a method called median() to the ArrayIns0.java in the insertSort.java program (Listing 3.3). This method should return the median value in

Java programming.  Java programming. 3.2 Add a method called median() to the ArrayIns0.java
in the insertSort.java program (Listing 3.3). This method should return the median
value in the array. (Recall that in a group of numbers half

3.2 Add a method called median() to the ArrayIns0.java in the insertSort.java program (Listing 3.3). This method should return the median value in the array. (Recall that in a group of numbers half are larger than the median and half are smaller.) 3.3 To the insertSort0.java program (Listing 3.3), add a method called noDups() that removes duplicates from a previously sorted array without disrupting the order. You can simply use main() to insert the data in sorted order. One can imagine schemes in which all the items from the place where a duplicate was discovered to the end of the array would be shifted down (left) one space every time a duplicate was discovered, but this would lead to slow O(N^2) time, at least when there were a lot of duplicates. In your algorithm, make sure no item is moved (left) more than once, no matter how many duplicates there are. This will give you an algorithm with O(N) time. You may not use a second array to remove the duplicates. Input : arr[] = {1, 2, 2, 3, 4, 4, 4, 5, 5} Output: arr[] = {1, 2, 3, 4, 5} new size = 5 class Insert Sort Appo { public static void main(String[] args) int maxSize = 100; // array size ArrayInso arr; // reference to array arr new ArrayInse(maxSize); 11 create the array arr.insert(77); // insert 18 items arr.insert(99); arr.insert(44); arr.insert(55); arr.insert(22); arr.insert(88); arr.insert(11); arr.insert(0); arr.insert(66); arr.insert(33); arr.display(); // display items arr.insertionsort(); 1/ insertion-sort then arr.display(); // display them again ArrayInse arr2 = new ArrayInse(maxSize); arr2.insert(1); arr2.insert(2); arr2.insert(2); arr2.insert(3); arr2.insert(4); arr2.insert(4); arr2.insert(4); arr2.insert(5); ar r2.insert(5); arr2.display(); 1/arr2.nodups(); arr2.display(); 1 // end main() } 1/ end class Insert SortApp // insert Sort.java // demonstrates insertion sort // to run this program: c>java InsertSortApp // ---- class ArrayInso private long[] a; // ref to array a private int nElems; // number of data items //---- public ArrayInso(int max) // constructor { = new long(max]; // create the array nElems = @; // no items yet } public void insert(long value) // put element into array { a[nelems] = value; // insert it nElems++; // increment size } public void display // displays array contents { for(int j=0; j0 && a[in-1] >= temp) // until one is smaller, { a[in] = a[in-1]; // shift item to right .in; // go left one position } a[in] = temp; // insert marked item } // end for 31/ end insertionsort() } // end class ArrayIns

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!