SelectSort
/**简单选择排序*/
#include<cstdio>
#include<algorithm>
using namespace std;
int a[]={5,2,1,3,4,6,8,9,10};
void f(int n){
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++)
if(a[j]<a[i]) swap(a[j],a[i]);
}
}
int main()
{
f(5);
for(int i=0;i<5;i++) printf("%d ",a[i]);
return 0;
}
SelectSort的更多相关文章
- 三大基础排序算法BubbleSort、SelectSort、InsertSort
public class Strategy { public static void main(String[] args) { int [] array=new int[]{26,25,15,42, ...
- 排序算法ONE:选择排序SelectSort
/** *选择排序: * 对冒泡排序的一个改进 * 进行一趟排序时,不用每一次都交换,只需要把最大的标示记下 * 然后再进行一次交换 */ public class SelectSort { /** ...
- 选择排序SelectSort
/** * * @author Administrator * 功能:选择排序法 */ package com.test1; import java.util.Calendar; public cla ...
- SelectSort 选择排序
//SelectSort (( O(n²))) public class TestSelectSort { public int[] selectSortArray(int[] arr){ int m ...
- 数据结构基础(1) --Swap & Bubble-Sort & Select-Sort
Swap的简单实现 //C语言方式(by-pointer): template <typename Type> bool swapByPointer(Type *pointer1, Typ ...
- 排序之选择排序(SelectSort)
package com.sort; /* * 选择排序 * 把第一位与其他数进行比较,这样每轮比较都会出现一个最大值或最小值 * 根据需要让升序或降序排列 */ public class Select ...
- C#数据结构与算法系列(十九):选择排序算法(SelectSort)
1.介绍 选择排序算法属于内部排序算法,是从欲排序的数据中,按指定的规则选出某一元素,再依规定交换位置达到排序的目的 时间复杂度:O(n^2) 双层for 2.思想 选择排序(select sorti ...
- python selectsort
# -*- coding: utf-8 -*-"""------------------------------------------------- File Name ...
- js实现四大经典排序算法
为了方便测试,这里写了一个创建长度为n的随机数组 function createArr(n) { var arr = []; while (n--) { arr.push(~~(Math.random ...
随机推荐
- vim 插件之solarized
solarized 其实算不上严格的插件,它只是一个主题,这个主题看起来还是很不错的.有一点,因为vim的最终效果还跟ubuntu终端配色有关,所以我们还需要进行其他的设置.具体过程如下 1.更改终端 ...
- Most common words
To find the most common words, we can apply the DSU pattern; most_common takes a histogram and retur ...
- Java容器源码解析之——LinkedList
我们直接从源码来分析LinkedList的结构: public class LinkedList<E> extends AbstractSequentialList<E> im ...
- 安卓开发--AsyncTask2
package com.cnn.imageasyncdemo01; import android.app.Activity; import android.content.Intent; import ...
- webi和universe
Universe是一个包含以下内容的文件: 1 一个或多个数据库中间件的连接参数. 2 称为对象的SQL结构,映射到数据库中的实际SQL结构,如列,表和数据库函数.其中对象是按类分组的.用户既可以看到 ...
- 使用Java操作Redis(一)
Redis是一款基于key-value的数据库服务器,安装完成后我们可以通过redis-cli使用Redis提供的命令完成各种操作.redis-cli实际上就是一款客户端,和redis-server建 ...
- PostgreSQL Replication之第八章 与pgbouncer一起工作(5)
8.5 维护 pgbouncer 除了我们在本章已经说明的,pgbouncer有一个很好的能够执行基本管理和监控任务的交互式管理界面. 它是如何工作的呢?pgbouncer提供给您一个虚假的称为pgb ...
- NodeJS学习笔记 (17)集群-cluster(ok)
cluster模块概览 node实例是单线程作业的.在服务端编程中,通常会创建多个node实例来处理客户端的请求,以此提升系统的吞吐率.对这样多个node实例,我们称之为cluster(集群). 借助 ...
- iOS开发——NSString小结
1.创建常量字符串. NSString *astring = @"This is a String!"; 2.创建空字符串,给予赋值. NSString *astring = ...
- HDU-2303 The Embarrassed Cryptographer 高精度算法(大数取模)
题目链接:https://cn.vjudge.net/problem/HDU-2303 题意 给一个大数K,和一个整数L,其中K是两个素数的乘积 问K的是否存在小于L的素数因子 思路 枚举素数,大数取 ...