选择排序
来源:互联网 发布:域名备案查询官网 编辑:程序博客网 时间:2024/06/02 00:05
//Selection-Sort
#include<iostream>
#include<algorithm>
using namespace std;
void selectionSort(int arr[], int n)
{
for (int i = 0; i < n; i++)
{
//寻找[i,n)区间里的最小值
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;
system("pause");
return 0;
}
#include<iostream>
#include<algorithm>
using namespace std;
void selectionSort(int arr[], int n)
{
for (int i = 0; i < n; i++)
{
//寻找[i,n)区间里的最小值
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;
system("pause");
return 0;
}
阅读全文
0 0
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 选择排序:
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- c++迭代器介绍
- 凛冬已至,然而我的颈椎还没有准备好 | 钛空舱世界保健日
- cmake常用指令-1 find_package与CMake如何查找链接库详解
- Nand Flash学习笔记0-浮栅的介绍
- 文章标题
- 选择排序
- 算法分析与设计第六周
- python np.mean(axis) tf.squeeze(x)
- 周报1
- 既是质数也是回文数
- 你好迪拜!今天我在GITEX 2017,锐捷在海外扬帆远航!
- 【头条】深度解读DataZoo四大优势 荣之联大数据的探索和创新
- Spark源码走读(一) —— Spark应用提交流程
- C++之数字容器装水问题(10)---《那些奇怪的算法》