#include <iostream> using namespace std; /** \ Insert Sort * * Key: * * reserve: tm = a[i] * * position: int j = i-1 * * move : while * */ template <typename T> void insertSort(T a[], int n) { T tm; for (int i = 1; i < n; i++) { tm = a[i]; int j = i-1; while (a[j] > tm && j >= 0){ a[j+1] = a[j]; j--; } a[j+1]=tm; } }
时间: 2024-10-10 02:12:00