#include
using namespace std;
void SelectionSort(int a[],int n)
{
int i,j;
for(int i=0;i<n-1;i++)
{ int min_index=i;
for(j=i;i<n;j++)
{
if(a[j]<a[min_index])
{
min_index=j;
}
}
swap(a[i],a[min_index]);
}
for(int i=0;i<n;i++)
{
cout<<a[i];
}
}
int main()
{
int a[1000],n,key;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
//This is the algorithm of selection sort.
SelectionSort(a,n);
return 0;
}
Output:
5
5 43 3 21 0
Process returned -1073741819 (0xC0000005) execution time : 22.662 s
Press any key to continue.