1. ## Java bubble sort

First off excuse that this isn't C++, but its super simple that i think anyone can help me ...just pretend its pseudocode

My question is, which is better? (and of course, is the 2nd code posted even considered bubble sort)

THANKS!

Heres standard bubble sort: It just goes through and makes the unsorted portion smaller each pass.
1rst code:
Code:
public static void bubbleSort(int[] arr) {

for(int i = arr.length - 1; i >= 1; i--){

for(int j = 0; j < i; j++)
{
if(arr[j] > arr[j+1])  {
//swap
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}

}

}

}
2nd code: (it keeps the unsorted portion the same size every pass but it stops 1 pass after it is sorted, while the first code continues till its done)
Code:
public static void sort(int[] arr)
{
int temp;
boolean ordered=false;

while(!ordered)
{
ordered=true;
for(int i=0;i<arr.length-1;++i)
{
if(arr[i]>arr[i+1])
{
ordered=false;
temp=arr[i];
arr[i]=arr[i+1];
arr[i+1]=temp;
}
}
}

}
THANKS AGAIN!

(I was also thinking that it depends on the dataset you receive... is there any why to "measure" how "bad" a dataset is?)

2. Java code belongs in the Tech Forum.

3. The basic bubblesort just continues, but of course, people notice these inefficiencies and next thing you know you have bubblesorts with varying degrees of optimizations.

They're still in the same group in terms of their complexity, AFAIK, but obviously the more optimized one's are also quicker than the most basic version.

For a laugh though, you have to check out BOZO sort - leave room around your work area so you can roll on the floor, laughing.