Current streak:
0 days
Longest streak:
4 days
Less
More
import java.util.Stack;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t != 0) {
int n = sc.nextInt();
Stack<Integer> st = new Stack<> ();
for(int i = 0; i < n; i++) {
int temp = sc.nextInt();
st.push(temp);
}
st = sort(st);
while(!st.empty()) {
int temp = st.pop();
System.out.print(temp + " ");
}
System.out.println();
t--;
}
}
public static Stack<Integer> sort(Stack<Integer> st) {
if(st.size() == 1)
return st;
int temp = st.pop();
st = sort(st);
st = insert(st, temp);
return st;
}
public static Stack<Integer> insert(Stack<Integer> st, int ele) {
if(st.empty() || ele <= st.peek()) {
st.push(ele);
return st;
}
int temp = st.pop();
st = insert(st, ele);
st.push(temp);
return st;
}
}