-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbogosort.java
More file actions
32 lines (31 loc) · 1 KB
/
bogosort.java
File metadata and controls
32 lines (31 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
import java.awt.*;
import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class bogosort{ // Answer is reverse sort.
static int mod = (int) 1e9 + 7;
public static void main(String[] args) throws Exception {
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();
for(int j=n;j>0;j--){
int max=Integer.MIN_VALUE;
int index=-1;
for(int i=0;i<j;i++){
if(j-arr[i]>max){
index=i;
max=j-arr[i];
}
}
int temp=arr[j-1];
arr[j-1]=arr[index];
arr[index]=temp;
}
for(int i=0;i<n;i++) System.out.print(arr[i]+" ");
System.out.println();
}
}
}