Skip to content

Instantly share code, notes, and snippets.

@hacksoldier
Last active September 29, 2015 12:11
Show Gist options
  • Select an option

  • Save hacksoldier/c122bda1e97facf3ac2c to your computer and use it in GitHub Desktop.

Select an option

Save hacksoldier/c122bda1e97facf3ac2c to your computer and use it in GitHub Desktop.
BubbleSort
/**
* Bubble Sort with Generics
*/
public void bubbleSort () throws EmptyArrayException {
for(int i=0; i < this.arraySort.length; i++)
for (int j=0; j < this.arraySort.length - 1; j++)
if(this.arraySort[j].compareTo(this.arraySort[j+1]) > 0) {
T key = this.arraySort[j];
this.arraySort[j] = this.arraySort[j+1];
this.arraySort[j+1] = key;
}
this.printArray();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment