Tweet
public class bubble
{
public static void bubble(int a[],int n)
{
int i,j;
for(i=0;i<n-1;i++)
for(j=0;j<n-1-i;j++)
if(a[j] > a[j+1])
{
int temp = a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
public static void main(String args[])
{
System.out.println();
System.out.println("Program of Bubble Sort :");
int a[]={34,89,-21,78,12,-6,67,45};
int i,n=8;
System.out.print("Given array :");
for(i=0;i<n;i++)
System.out.print(a[i] + " ");
System.out.println();
bubble(a,n);
System.out.print("Sorted array : ");
for(i=0;i<n;i++)
System.out.print(a[i] + " ");
System.out.println();
}
}
Bubble Sort in Java
Posted by
LAHAUL SETH
~
Bubble Sort in Java
2011-11-29T11:09:00+05:30
LAHAUL SETH
Java
|
Sorting
|
Comments
Bubble Sort in Java
2011-11-29T11:09:00+05:30
LAHAUL SETH
Java
|
Sorting
|