Skip to content

Instantly share code, notes, and snippets.

@mahmoudhossam
Created August 19, 2011 16:44
Show Gist options
  • Save mahmoudhossam/1157291 to your computer and use it in GitHub Desktop.
Save mahmoudhossam/1157291 to your computer and use it in GitHub Desktop.
Bubble Sort attempt#1
import java.util.Arrays;
public class BubbleSort {
public static void main(String[] args){
int[] numbers = {9, 2, 7, 4, 6};
int[] sorted = sort(numbers);
System.out.println(Arrays.toString(sorted));
}
public static int[] sort(int[] input){
for(int i = 0; i < input.length-1; i++){
int a = input[i];
int b = input[i+1];
if(a > b){
input[i] = b;
input[i+1] = a;
}
}
return input;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment