运行结果:#include <iostream> using namespace std; void printarry(int *a) { int i; for (i = 0; i < 10;i++) { //cout << "排序前:" << endl; cout << a[i] << " "; } } int main() { int i, j, tmp; int a[10] = { 12, 45, 46, 7, 8, 95, 64, 21, 78, 10 }; printarry(a); cout << endl; for (i = 0; i < 10;i++) { for (j = i + 1; j < 10;j++) { if (a[i]<a[j]) { tmp = a[j]; a[j] = a[i]; a[i] = tmp; } } } printarry(a); cout << endl; system("pause"); return 0; }
经典排序算法——选择排序法
最新推荐文章于 2023-06-09 22:42:06 发布