Skip to content

Commit da10a98

Browse files
authored
Merge pull request bhrigukansra#170 from PSakila/master
Bubblesort_17251A05H5.java
2 parents 50e1268 + 93d3481 commit da10a98

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import java.util.Scanner;
2+
class BubbleSort{
3+
public static void main(String args[]){
4+
//Scanning the elements of the array
5+
Scanner sc=new Scanner(System.in);
6+
System.out.println("enter no. of elements");
7+
int n=sc.nextInt();
8+
int[] a=new int[n];
9+
for(int i=0;i<n;i++) a[i]=sc.nextInt();
10+
//Sorting
11+
for (int c = 0; c < ( n - 1 ); c++) {
12+
for (int d = 0; d < n - c - 1; d++) {
13+
if (a[d] >a[d+1])
14+
{
15+
int swap= a[d];
16+
a[d] = a[d+1];
17+
a[d+1] = swap;
18+
}
19+
}
20+
}
21+
for(int j=0;j<a.length;j++)
22+
System.out.print(a[j]+" ");
23+
System.out.println();
24+
25+
26+
}
27+
}

0 commit comments

Comments
 (0)