SORT 6


TEST CASE 1 

INPUT

2
5
2 8 7 1 5
6
7 -2 3 4 9 -1
OUTPUT
1 2 5 
-2 -1 3 4 

TEST CASE 2 

INPUT

1
6
4 8 -1 6 7 -3
OUTPUT
-3 -1 4 6


#include <iostream>
using namespace std;
void sort(int a[],int n)
{
  int m;
  for(int i=0;i<n-1;i++)
  {
    m=i;
    for(int j=i+1;j<n;j++)
      if(a[j]<a[m])
        m=j;
    int t=a[i];
    a[i]=a[m];
    a[m]=t;
  }
}
void display(int a[],int n)
{
  for(int i=0; i<n-2; i++)
  cout<<a[i]<<" ";
  cout<<endl;
}
int main() {
  int t;
  cin>>t;
  while(t)
  {
    int n; 
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++)
    {cin>>a[i];}
    sort(a,n);
    display(a,n);
    t--;
  }
  return 0;
}

Comments

Popular posts from this blog

AR1

SER12

AR15