Insertion sort Challenge

Code works fine in ide but when submitting in challenge windows showing unexpected outputs

#include
using namespace std;
void insertion(int a[],int n)
{
int i,j,smallest;
for (i=1;i<n;i++)
{
smallest=i;
for (j=i-1;j>=0;j–)
{
if(a[j]>a[smallest])
{
swap(a[j],a[smallest]);
smallest=j;
}
}
}
}
int main()
{

int n;
cin>>n;
int a[n];
int i;
for (i=0;i<n;i++)
{
cin>>a[i];
}
insertion (a,n);

for (i=0;i<n;i++)
{
cout<<a[i]<<endl;
}
}

The code given here has many compilation errors( like header file missing,etc). Please correct them first.

Ran successfully
was submitting to the ide in wrong way
Thanks !

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.