Answered step by step
Verified Expert Solution
Link Copied!

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: C>java BubbleSortApp
////////////////////////////////////////////////////////////////
class ArrayBub
{
private long[] a; // ref to array a
private int nElems; // number of data items
//--------------------------------------------------------------
public ArrayBub(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; j1; out--)// outer loop (backward)
for(in=0; in a[in+1])// out of order?
swap(in, in+1); // swap them
}// end bubbleSort()
public void selectionSort()
{
int out, in, min;
for(out=0; 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()
public void oddEvenSort()
{
}
//--------------------------------------------------------------
private void swap(int one, int two)
{
long temp = a[one];
a[one]= a[two];
a[two]= temp;
}
//--------------------------------------------------------------
}// end class ArrayBub
////////////////////////////////////////////////////////////////
class BubbleSortApp
{
public static void main(String[] args)
{
int maxSize =100000; // array size
ArrayBub arr; // reference to array
arr = new ArrayBub(maxSize); // create the array
for(int j=0; j

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_2

Step: 3

blur-text-image_3

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

Practical Neo4j

Authors: Gregory Jordan

1st Edition

1484200225, 9781484200223

More Books

Students also viewed these Databases questions