-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSortArray.java
More file actions
26 lines (26 loc) · 771 Bytes
/
SortArray.java
File metadata and controls
26 lines (26 loc) · 771 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
import java.util.Scanner;
public class SortArray {
public static void main(String[] main){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt(), l = sc.nextInt(), r = sc.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++){
a[i] = sc.nextInt();
}
sort(a, l, r);
for (int i = 0; i < n; i++) {
System.out.printf("%d ", a[i]);
}
}
private static void sort(int a[], int l, int r){
for (int i = r; i > l; i--){ //bubble sort
for (int j = l; j < i; j++){
if (a[j] > a[j + 1]){
int t = a[j];
a[j] = a[j+1];
a[j+1] = t;
}
}
}
}
}