Java Program :
class ascending
{
static void compute(int[] a)
{
int i,j,k;
System.out.print("Original array : ");
array.display(a);
System.out.print("\n\nLength : "+a.length);
for(i=0;i<a.length-1;i++)
{
for(j=0;j<a.length-1;j++)
{
if(a[j]>a[j+1])
{
k=a[j];
a[j]=a[j+1];
a[j+1]=k;
}
}
}
System.out.print("\n\nAscending data : ");
for(i=0;i<a.length;i++)
System.out.print(a[i]+" ");
}
}
class ascending
{
static void compute(int[] a)
{
int i,j,k;
System.out.print("Original array : ");
array.display(a);
System.out.print("\n\nLength : "+a.length);
for(i=0;i<a.length-1;i++)
{
for(j=0;j<a.length-1;j++)
{
if(a[j]>a[j+1])
{
k=a[j];
a[j]=a[j+1];
a[j+1]=k;
}
}
}
System.out.print("\n\nAscending data : ");
for(i=0;i<a.length;i++)
System.out.print(a[i]+" ");
}
}
Thanks for sharing this Java Bubble Sort Algorithm .
ReplyDeleteBhai i ka loop 0 se a.length-1tak ka hoga
ReplyDeleteNo, its okay.
ReplyDeleteNice.Thanks for sharing useful java program.
ReplyDeleteThanks
Cheers,
https://www.flowerbrackets.com/bubble-sort-java/