rendered paste bodypublic class bubbleSort
{
public static void swapArrayItems (int[] list, int pos1, int pos2)
{ int temp = list[pos1];
list[pos1] = list[pos2];
list[pos2] = temp;
}
public static void main(String[] args)
{
int numItems = list.length;
boolean notSorted = true;
while (notSorted && (numItems >= 2))
{
notSorted = false;
for (int i = 0; i < numItems - 1; ++i)
{
if( list[i] > list[i+1])
{
swapArrayItems(list, i, i+1);
//a swap occurred so possibly not sorted
notSorted = true;
}
}
--numItems;
}
}
}