selectionSort
来源:互联网 发布:表情呆滞面部僵硬知乎 编辑:程序博客网 时间:2024/06/06 19:24
向量的选择排序类 (C++ 实现)
#include <iostream>#include <vector>#include <string>#include <sstream>using namespace std;class selectionSort{public: selectionSort(vector<int> &); void swap(int *, int *);};int main(){ vector<int> v; int n; string s; getline(cin, s); stringstream ss(s); while (ss >> n) { v.push_back(n); } selectionSort sel(v); for (unsigned int i = 0;i < v.size();i++) { cout << v[i] << " "; } cout << endl; return 0;}selectionSort::selectionSort(vector<int> &v){ int s = v.size(); for (int i = 0;i < s - 1;i++) { int min = i; for (int j = i + 1;j < s;j++) { if (v[min] > v[j]) { min = j; } } swap(&v[i], &v[min]); }}void selectionSort::swap(int *p1, int *p2){ int temp = *p1; *p1 = *p2; *p2 = temp;}
1 0
- SelectionSort
- selectionSort
- selectionSort
- selectionSort
- selectionSort
- SelectionSort
- selectionSort
- Golang - SelectionSort
- 选择排序SelectionSort
- 快速排序(SelectionSort)
- 选择排序-SelectionSort
- 选择排序 - SelectionSort
- 算法基础复习-SelectionSort
- 选择排序SelectionSort
- 【代码积累】SelectionSort
- bubblesort and selectionsort
- 选择排序(1)SelectionSort
- SelectionSort -- 选择排序(C++)
- B树、B+树
- linux ./configure 的参数详解
- 【Django】-- django.db.migrations.exceptions.InconsistentMigrationHistory
- onCreateView 与onActivityCreated 的区别
- 二叉树先序遍历(包含递归和非递归(2种方法))
- selectionSort
- 【数据结构基础】选择排序法
- ubuntu系统安装deb格式的软件(以lantern为例)
- linux系统中如何进入退出vim编辑器,方法及区别
- shell中输入重定向,输出重定向,管道
- 推荐系统之基于用户的协调过滤
- Shiro 学习笔记(2)—— Jdbc Realm
- error LNK2019解决方法
- spring4 集成JMX监控