Skip to content

Instantly share code, notes, and snippets.

@tmosest
Created January 31, 2017 22:13
Show Gist options
  • Save tmosest/6062e065ad24262867bdcf77d3f26ea1 to your computer and use it in GitHub Desktop.
Save tmosest/6062e065ad24262867bdcf77d3f26ea1 to your computer and use it in GitHub Desktop.
Bubble Sort in Java
// Worste case is n^2 best case is n;
public static void BubbleSort(int[] array)
{
int j;
boolean flag = true;
int temp;
while(flag) {
flag = false;
for(j = 0; j < num.lenght - 1; j++) {
temp = num[j];
num[j] = num[j + 1];
num[j + 1] = temp;
flag = true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment