Question: / / bubbleSort.java / / demonstrates bubble sort / / to run this program: C > java BubbleSortApp / / / / / / /
bubbleSort.java
demonstrates bubble sort
to run this program: Cjava BubbleSortApp
class ArrayBub
private long a; ref to array a
private int nElems; number of data items
public ArrayBubint max constructor
a new longmax; create the array
nElems ; no items yet
public void insertlong value put element into array
anElems value; insert it
nElems; increment size
public void display displays array contents
forint j; j; out outer loop backward
forin; in ain out of order?
swapin in; swap them
end bubbleSort
public void selectionSort
int out, in min;
forout; out && ain temp until one is smaller,
ain ain; shift item to right
in; go left one position
ain temp; insert marked item
end for
end insertionSort
public void oddEvenSort
private void swapint one, int two
long temp aone;
aone atwo;
atwo temp;
end class ArrayBub
class BubbleSortApp
public static void mainString args
int maxSize ; array size
ArrayBub arr; reference to array
arr new ArrayBubmaxSize; create the array
forint j; j
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
