Skip to content

Commit

Permalink
Merge pull request #172 from MananAg29/patch-9
Browse files Browse the repository at this point in the history
Create BubbleSort.java
  • Loading branch information
fineanmol committed Oct 1, 2021
2 parents cd3aa79 + eae0ef3 commit e07ca3c
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import java.util.*;
class BubbleSort
//select a cell and compare it with next cell
{
public static void main(String args[])
{
Scanner d=new Scanner(System.in);
int i,j,t,k,min,p,n;
n=d.nextInt();
int a[]=new int[n];
for(i=0;i<n;i++)
a[i]=d.nextInt();
for(i=0;i<n;i++)//0 ->n
{
for(j=0;j<n-1-i;j++)//0 ->n-1-i
{
if(a[j]>a[j+1])//next element
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
for(i=0;i<n;i++)
System.out.print(a[i]+" ");
}
}

0 comments on commit e07ca3c

Please sign in to comment.