Created
August 19, 2011 16:44
-
-
Save mahmoudhossam/1157291 to your computer and use it in GitHub Desktop.
Bubble Sort attempt#1
This file contains hidden or 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
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