//直接插入排序函数模板templatevoid insertionSort(T a[], int n){ int i, ; T temp; for (int i = 1; i < n; i++) { int j = i; T temp = a[i]; while (j > 0 && temp < a[j-1]) { a[j] = a[j - 1]; j--; } a[j] = temp; }}//简单选择排序函数模板template void mySwap(T &x, T &y){ T temp = x; x = y; y = temp;}template void selectionSort(T a[], int n){ for (int i = 0; i < n - 1; i++) { int leastIndex = i; for (int j = i + 1; j < n; j++) { if (a[j] < a[leastIndex]) { leastIndex = j; } } mySwap(a[i], a[leastIndex]); }}//冒泡排序template void bubbleSort(T a[], int n){ int i = n - 1; while (i > 0) { int lastExchangeIndex = 0; for (int j = 0; j < i; j++) { if (a[j + 1] < a[j]) mySwap(a[j], a[j + 1]); lastExchangeIndex = j; } i = lastExchangeIndex; }}