Skip to content

Instantly share code, notes, and snippets.

@nivdul
Last active September 14, 2018 09:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nivdul/94d18e07c7c8039454a7da5ba6f12fd9 to your computer and use it in GitHub Desktop.
Save nivdul/94d18e07c7c8039454a7da5ba6f12fd9 to your computer and use it in GitHub Desktop.
BubbleSortExample
public class BubbleSortExample {
static int[] bubbleSort(int[] arr) {
int n = arr.length;
int temp = 0;
for(int i=0; i < n; i++){
for(int j=1; j < (n-i); j++){
if(arr[j] < arr[j-1]){
//swap elements
temp = arr[j];
arr[j] = arr[j-1];
arr[j-1] = temp;
}
}
}
return arr;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment