void SelectionSort_Caitien(int a[], int n)
{
int minIndex;
int maxIndex;
for(int i=0;i<=(n-1)/2;i++)
{
minIndex=i;
maxIndex=i;
for(int j=i+1;j<n-i;j++)
{
if(a[j]<a[minIndex])
minIndex=j;
if (a[j]>a[maxIndex])
maxIndex=j;
}
//Hoan vi a[i], a[minIndex]
if(maxIndex==i)
maxIndex=minIndex;
swap(a[i],a[minIndex]);
swap(a[n-1-i],a[maxIndex]);
}
}
Sign up here with your email
ConversionConversion EmoticonEmoticon