Last active
September 14, 2018 09:07
-
-
Save nivdul/94d18e07c7c8039454a7da5ba6f12fd9 to your computer and use it in GitHub Desktop.
BubbleSortExample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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