-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathH. Sorting
More file actions
42 lines (35 loc) · 1 KB
/
H. Sorting
File metadata and controls
42 lines (35 loc) · 1 KB
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
32
33
34
35
36
37
38
39
40
41
42
import java.util.*;
public class now{
public static void SelectionSort(int arr[]){
int n = arr.length;
for (int i = 0; i < n-1; i++){
int min_idx = i;
for (int j = i+1; j < n; j++){
if (arr[j] < arr[min_idx])
min_idx = j;
}
int temp = arr[min_idx];
arr[min_idx] = arr[i];
arr[i] = temp;
}
}
public static void printArray(int arr[]){
for(int i=0;i<arr.length;i++){
System.out.print(arr[i]+" ");
}
System.out.println();
}
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int size;
size=sc.nextInt();
int arr[] = new int[size];
for(int i=0;i<size;i++){
arr[i]=sc.nextInt();
}
SelectionSort(arr);
printArray(arr);
sc.close();
}
}
link - https://codeforces.com/group/MWSDmqGsZm/contest/219774/problem/H