-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #172 from MananAg29/patch-9
Create BubbleSort.java
- Loading branch information
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
Program's_Contributed_By_Contributors/Java_Programs/Sorts/BubbleSort.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]+" "); | ||
} | ||
} |