-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBubble_Sort.java
More file actions
31 lines (30 loc) · 838 Bytes
/
Bubble_Sort.java
File metadata and controls
31 lines (30 loc) · 838 Bytes
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.*;
public class Bubble_Sort {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int a[] = new int[1001];
for(int i=0;i<n;i++){
a[i] = in.nextInt();
}
int k = 1;
for(int i=0;i<n;i++){
boolean ok = true;
for(int j=0;j<n-1;j++){
if(a[j]>a[j+1]){
int t = a[j];
a[j] = a[j+1];
a[j+1] = t;
ok = false;
}
}
if(!ok){
System.out.print("Buoc "+k+": ");
k++;
for(int h = 0;h<n;h++)
System.out.print(a[h]+" ");
System.out.println();
}
}
}
}