Hi, I am trying to calculate the amount of time it takes to complete an ascending or descending bubblesort. I have both a worker class and an application class as such:
Worker class:
public void abubbleSort()
{
int out, in;
for(out=nElems-1; out>1; out--) // outer loop (backward)
for(in=0; in<out; in++) // inner loop (forward)
if( a[in] > a[in+1] ) // out of order?
swap(in, in+1); // swap them
} // end bubbleSort()
Application Class:
Date start = new Date();
if (s.charAt(0) == 'A')
arr.abubbleSort();
else
arr.dbubbleSort();
Date stop = new Date ();
long elapsed = stop.getTime() - start.getTime();
arr.display(numberToPrint); // display items
Is there anyway I can streamline this?? All suggestions would be appreciated. Thanks.
Worker class:
public void abubbleSort()
{
int out, in;
for(out=nElems-1; out>1; out--) // outer loop (backward)
for(in=0; in<out; in++) // inner loop (forward)
if( a[in] > a[in+1] ) // out of order?
swap(in, in+1); // swap them
} // end bubbleSort()
Application Class:
Date start = new Date();
if (s.charAt(0) == 'A')
arr.abubbleSort();
else
arr.dbubbleSort();
Date stop = new Date ();
long elapsed = stop.getTime() - start.getTime();
arr.display(numberToPrint); // display items
Is there anyway I can streamline this?? All suggestions would be appreciated. Thanks.