All pastes #280622 Raw Edit

Stuff

public text v1 · immutable
#280622 ·published 2006-12-16 01:16 UTC
rendered paste body
public 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)
	{


        } 

        public static void sortTheDamnThing(int[] list) 
        {
		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;
		}
	}
		
}