forked from VivekDubey9/Competitive-Programming-Algos
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbubbleSort
31 lines (27 loc) · 842 Bytes
/
bubbleSort
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.util.Scanner;
public class BubbleSort_006 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// int n = a.length;
System.out.println("Enter the No. of elements you want to sort : ");
int m = sc.nextInt();
int a[] = new int[m];
System.out.println("Enter the elements :");
for (int i = 0; i < m; i++) {
a[i] = sc.nextInt();
}
for (int i = 0; i < (m - 1); i++) {
for (int j = 0; j < (m - 1); j++) {
if (a[j + 1] < a[j]) {
int temp = a[j + 1];
a[j + 1] = a[j];
a[j] = temp;
}
}
}
for (int item : a) {
System.out.print(item + " ");
}
sc.close();
}
}