# Chandu and his Girlfriend Merge Sort

QUESTION

Chandu’s girlfriend loves arrays that are sorted in non-increasing order. Today is her birthday. Chandu wants to give her some sorted arrays on her birthday. But the shop has only unsorted arrays. So, Chandu bought T unsorted arrays and is trying to sort them. But, he doesn’t have much time to sort the arrays manually as he is getting late for the birthday party. So, he asked you to write a program to sort the T arrays in non-increasing order. Help him, or his girlfriend will kill him.\n\nInput:\nFirst line contains an integer T, denoting the number of test cases.\nFirst line of each test case contains an integer N, denoting the size of the array.\nSecond line contains N space separated integers, denoting the array elements Ai.\n\nOutput: \nFor each test case, print the sorted array in non-increasing order.\n\nConstraints:\n1 <= T <= 100\n1 <= N <= 105\n0 <= Ai <= 109.

“TESTCASE_1”: “2\n5\n2 5 2 4 3\n5\n5 4 2 3 1\n###—###SEPERATOR—###—\n5 4 3 2 2 \n5 4 3 2 1”, “TESTCASE_2”: “5\n5\n12938 12038138 12318231 129480498 9722341\n3\n9 8 2\n3\n1 2 3\n8\n7 6 19 2931 341123 66281 4123 1\n5\n983274 23231 3113124 234 123\n###—###SEPERATOR—###—\n129480498 12318231 12038138 9722341 12938 \n9 8 2 \n3 2 1 \n341123 66281 4123 2931 19 7 6 1 \n3113124 983274 23231 234 123 “, “TESTCASE_3”: “6\n1\n1\n2\n4 1\n2\n3 4\n5\n912 28 10 10 1\n6\n2 3 5 1 12 2\n5\n223 123 123 12894134 120123897\n###—###SEPERATOR—###—\n1 \n4 1 \n4 3 \n912 28 10 10 1 \n12 5 3 2 2 1 \n120123897 12894134 223 123 123 “, “TESTCASE_4”: “0\n###—###SEPERATOR—###—\n0”, “TESTCASE_5”: “0\n###—###SEPERATOR—###—\n0

``````#include <iostream>
#include<bits/stdc++.h>
using namespace std;
void sortArray(int a[],int n){

for(int i=0;i<n;i++){
for(int j=0;j<n-i-1;j++){
if(a[j]<a[j+1]){
int temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}

}

int main()
{	int t;
cin>>t;
for(int i=0;i<t;i++){
int n;
cin>>n;
int a[n];
for(int j=0;j<n;j++){
cin>>a[j];
}
sortArray(a,n);
for(int j=0;j<n;j++){
cout<<a[j]<<" ";
}
cout<<endl;
}

return 0;
}``````

#### Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.