选择排序

来源:互联网 发布:js获取子节点个数 编辑:程序博客网 时间:2024/05/17 01:34

//选择排序

include

include

using namespace std;

void selectionSort(int arr[], int n) {
for (int i = 0; i < n; i++) {重点内容
int minIndex = i;
for (int j = i + 1; j < n; j++)
if (arr[j] < arr[minIndex])
minIndex = j;

    swap(arr[i], arr[minIndex]);}

}

int main()
{
int a[10] = { 10,9,8,7,6,5,4,3,2,1 };
selectionSort(a, 10);
for (int i = 0; i < 10; i++)
cout << a[i] << ” “;
cout << endl;
return 0;
}

0 0
原创粉丝点击