Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

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.)

Insert Sort java --

class InsertSortApp0 { public static void main(String[] args) { int maxSize = 100; // array size ArrayIns0 arr; // reference to array arr = new ArrayIns0(maxSize); // create the array

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

arr.insertionSort(); // insertion-sort them

arr.display(); // display them again ArrayIns0 arr2 = new ArrayIns0(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); arr2.insert(5); arr2.display(); //arr2.noDups(); arr2.display(); } // end main() } // end class InsertSortApp

ArrayIns0 java --

// insertSort.java // demonstrates insertion sort // to run this program: C>java InsertSortApp //-------------------------------------------------------------- class ArrayIns0 { private long[] a; // ref to array a private int nElems; // number of data items //-------------------------------------------------------------- public ArrayIns0(int max) // constructor { a = new long[max]; // create the array nElems = 0; // 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; j

for(out=1; out0 && 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 } // end insertionSort() //-------------------------------------------------------------- } // end class ArrayIns ////////////////////////////////////////////////////////////////

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

Conceptual Database Design An Entity Relationship Approach

Authors: Carol Batini, Stefano Ceri, Shamkant B. Navathe

1st Edition

0805302441, 978-0805302448

More Books

Students also viewed these Databases questions

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago