selsort1.cpp

来自「一本全面剖析C++数据结构算法的书籍」· C++ 代码 · 共 24 行

CPP
24
字号
// selection sort#include <iostream.h>#include "swap.h"#include "max.h" // max of n elementstemplate<class T>void SelectionSort(T a[], int n){// Sort the n elements a[0:n-1].   for (int size = n; size > 1; size--) {      int j = Max(a, size);      Swap(a[j], a[size - 1]);      }}void main(void){   int y[10] = {3, 2, 4, 1, 6, 9, 8, 7, 5, 0};   SelectionSort(y,10);   for (int i=0; i<10; i++)      cout << y[i] << ' ';   cout << endl;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?