BubbleSort.java
public class BubbleSort
{
public static void main(String[] args)
{
int array[];
array=new int[]{5,7,9,3,1};
int l=array.length;
//Sorting
for (int i=0;i<l-1 ;i++ )
{
for (int j=0;j<l-1 ;j++ )
{
if(array[j]>array[j+1])
{
int temp=array[j];
array[j]=array[j+1];
array[j+1]=temp;
}
}
}
//Display
for (int k=0;k<=l-1 ;k++ )
{
System.out.print(""+array[k]+"\t\t");
}
}
}
Bubble Sort |
0 comments:
Post a Comment