Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Section 3.3 1- Add the following method to the Insertion Sort Program given in Section 3.3: Add a method called noDups() that removes duplicates from

Section 3.3

image text in transcribed

image text in transcribed

1- Add the following method to the Insertion Sort Program given in Section 3.3:

Add a method called noDups() that removes duplicates from a previously sorted array without disrupting the order. Use the insertionSort() method to sort the data. Recall that after removing the duplicates, the resulting array cannot have any holes, i.e., be sure to shift the elements such that all elements in the array are in contiguous locations.

Add appropriate code to the main() method to exercise the noDups() method.

Sample I/O:

image text in transcribed

4 5 public class ArrayIns { private long[] a; private int nElems; // ref to array a // number of data items public ArrayIns (int max) // constructor a = new long(max]; nElems = 0; // create the array public void insert (long value) // put element into array a[nElems] = value; nElems++; = = = = = = = = public void display() // displays array contents HHHHHHNNNNNNNNNNMMMM for(int j=0; j0 && a[in-1] >= temp) // remove marked item // start shifts at out // until one is smaller, a[in] = a[in-1]; --in; // shift item to right // go left one position " a [in] = temp; // insert marked item 1 2 3 /** + InsertSortApp.java */ public class Insert SortApp public static void main(String[] args) - int maxSize = 100; ArrayIns arr; arr = new ArrayIns (maxSize); // reference to array // create the array // insert 10 items arr.insert (77); 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); - System.out.print("Array before sorting: "); arr.display(); arr.insertionSort(); // insertion-sort them System.out.print("Array after sorting: "); arr.display(); - General Output --------------------Configuration: Insert SortApp - JDK vergic Array before sorting: 77 99 44 55 22 88 11 0 66 33 Array after sorting: 0 11 22 33 44 55 66 77 88 99 Process completed. General Output ------------Configuration: ---------- > Array before sorting: 77 99 44 55 22 88 11 11 44 33 Array after sorting: 11 11 22 33 44 44 55 77 88 99 Array after removing duplicates: 11 22 33 44 55 77 88 99

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

Database Design Application Development And Administration

Authors: Mannino Michael

5th Edition

0983332401, 978-0983332404

More Books

Students also viewed these Databases questions