My Profile Photo

Cory Kelly


CoryPlusPlus - Cory with classes


A blog documenting solutions to some interesting problems


Bubble Sort

Bubble Sort Class


public class BubbleSortImpl extends SortImpl {

	public void sort(int[] array) {
		if(!sizeValid(array))
			return;
		for(int i = 0; i < array.length; i++)
		{
			for(int j = 1; j < array.length - i; j++)
			{
				if(array[j] < array[j-1])
				{
					//Swap
					array[j] = array[j] ^ array[j-1];
					array[j-1] = array[j-1] ^ array[j];
					array[j] = array[j] ^ array[j-1];
				}
			}
		}
	}

}
comments powered by Disqus