Answered step by step
Verified Expert Solution
Question
1 Approved Answer
/ / 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started