A Bubble-Sort algorithm compares neighbors in an
array
and exchanges them if they are out of order.
It must go through the
entire array, and then through the
entire array again, and again until
finished. It may take
as many passes as there are
numbers in the array.
Write an algorithm to perform a Bubble-Sort on an array of ints.
public void bubbleSort( int[] data )
{
for(int pass = 0; pass <
data.length; pass = pass +
1)
{
for(int x = 0; x
< data.length - 1; x =
x+1)
{
if (
data[x] > data[x+1]
)
{
int
temp =
data[x];
data[x] =
data[x+1];
data[x+1] =
temp;
}
}
}
}