#include<iostream>
using namespace std;
template<typename T>
void exchange(T& a, T& b)
{
int temp;
temp = a;
a = b;
b = temp;
}
template<typename T>
int findMaxIndex(T* a, int begin, int end)
{
int maxIndex;
int n = sizeof(a) / sizeof(a[0]);
maxIndex = begin;
for (int i = begin; i <= end; i++)
{
if (a[maxIndex] < a[i])
{
maxIndex=i;
}
}
return maxIndex;
}
template<typename T>
void selectSort(T* a,int n)
{
for (int i = 0; i < n; i++)
{
int index = findMaxIndex(a, 0, n - i - 1);
//cout << index << endl;
swap(a[index], a[n - i - 1]);
}
}
int main()
{
int a[] = { 4,5,6,7823,214,6,8 };
selectSort(a,sizeof(a)/sizeof(a[0]));
for (int i=0;i<sizeof(a)/sizeof(a[0]);i++)
{
cout << a[i]<<ends;
}
system("pause");
return 0;
}
11-04