template<typename T>
void SelectSort(list<T>& container)
{
std::list<T>::iterator it_min = container.begin();//待放入最小值的位
std::list<T>::iterator it_temp = it_min;//暂存最小值
std::list<T>::iterator it_test = it_min;//滑动指针
it_test++;
do
{
while (it_test!=container.end())
{
if (*it_temp > *it_test)
{
it_temp = it_test;
}
it_test++;
}
swap(*it_temp, *it_min);
it_min++;
//将test位放在min位后1位
it_test = it_min;
it_test++;
//默认min为最小位
it_temp = it_min;
} while (it_test != container.end());
}
时间: 2024-10-09 00:04:11