简单选择排序
#include <iostream>
using namespace std;void sawp(int& a, int& b)
{int temp = 0;temp = a;a = b;b = temp;
}void selection_sort(int array[], int size)
{for (int i = 0; i < size; i++){int min = i;for (int j = i + 1; j < size; j++){if (array[j] < array[min]){min = j;}}sawp(array[i], array[min]);}cout << "简单选择排序后数据如下:" << endl;for (int i = 0; i < size; i++){cout << array[i] << " ";}
}// 3 5 1 33 12 45 65
int main(void)
{int array[] = { 3,5,1,33,12,45,65};selection_sort(array, 7);return 0;
}