Skip to content

Instantly share code, notes, and snippets.

@nifrasismail
Created May 12, 2015 13:30
Show Gist options
  • Save nifrasismail/859a16cfe79ca4707356 to your computer and use it in GitHub Desktop.
Save nifrasismail/859a16cfe79ca4707356 to your computer and use it in GitHub Desktop.
Bubble_Sort
public class Bubble_Sort {
int[] A;
int length;
public void read(){
int[] B = {48,25,36,95,96,32,31,32};
A = B;
length = A.length;
}
public void sort(){
for (int i = 0; i < A.length-1; i++) {
for (int j = 0; j < A.length-1-i; j++) {
if(A[j] > A[j+1]){
int temp = A[j];
A[j] = A[j+1];
A[j+1] = temp;
}
}
}
}
public void print(){
for (int i = 0; i < A.length; i++) {
System.out.print(A[i] + " ");
}
}
public static void main(String[] args){
Bubble_Sort B = new Bubble_Sort();
B.read();
B.sort();
B.print();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment