-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint.java
55 lines (47 loc) · 1008 Bytes
/
print.java
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
43
44
45
46
47
48
49
50
51
52
53
54
55
import java.util.*;
class selection_sort
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t>0)
{
int n = sc.nextInt();
int arr[] = new int[n];
for(int i=0;i<n;i++)
{
arr[i] = sc.nextInt();
}
Solution obj = new Solution();
obj.selectionSort(arr, n);
for(int i=0;i<n;i++)
System.out.print(arr[i]+" ");
System.out.println();
t--;
}
}
}
// } Driver Code Ends
class Solution
{
int select(int arr[], int i)
{
// code here such that selectionSort() sorts arr[]
int min_idx = i;
for(int j=i;j<=arr.length-1;j++){
if(arr[min_idx]>arr[j]) min_idx = j;
}
int temp = arr[min_idx];
arr[min_idx] = arr[i];
arr[i] = temp;
return 0;
}
void selectionSort(int arr[], int n)
{
//code here
for(int i=0;i<n-1;i++){
select(arr,i);
}
}
}