Bubble sort algorithm is a simplest way of sorting array elements.Most of another algorithms are more efficient than bubble sort algorithm..Worst case and average case time complexity is (n^2).Let's consider how to implement bubble sort algorithm.
class buble_sort{
public static void main(String a[]){
int[] num={7,9,2,4,5,6,3};
int i,j,tmp;
for(i=0;i<num.length;i++){
for(j=0;j<num.length-i;j++){
if(j==(num.length-1)){
break;
}
else{
if(num[j]>num[j+1]){
tmp=num[j];
num[j]=num[j+1];
num[j+1]=tmp;
}
}
}
}
for(i=0;i<num.length;i++){
System.out.print(num[i]+" ");
}
}
}