交互设计算法基础(2) - Selection Sort
int[] selection_sort(int[] arr) {
int i, j, min, temp, len=arr.length;
for (i=0; i<len-1; i++) {
min=i;
for (j=i+1; j<len; j++) {
if (arr[min]<arr[j]) {
min=j;
}
temp = arr[min];
arr[min] = arr[i];
arr[i]=temp;
}
}
return arr;
}
void draw() {
noLoop();
int[] test = {15, 33, 46, 22, 70};
println(selection_sort(test));
}
选择排序,就是依序拿相邻的两个元素做比较,大的那个放下面,小的堆上面,一轮过后就排好了,O(N^2)。
交互设计算法基础(2) - Selection Sort的更多相关文章
- 交互设计算法基础(1) - Binary Search
int binary_search(int[] list, int item) { int low = 0; int high = list.length-1; while (low <= hi ...
- 交互设计算法基础(3) - Quick Sort
int pivotIndex, pivot, swapIndex; void swap(int[] arr, int x, int y) { int temp = arr[x]; arr[x] = a ...
- 交互设计算法基础(4) - Hash Table
import java.util.Map; // Note the HashMap's "key" is a String and "value" is an ...
- 排序算法--选择排序(Selection Sort)_C#程序实现
排序算法--选择排序(Selection Sort)_C#程序实现 排序(Sort)是计算机程序设计中的一种重要操作,也是日常生活中经常遇到的问题.例如,字典中的单词是以字母的顺序排列,否则,使用起来 ...
- [算法] 选择排序 Selection sort
选择排序(Selection sort)是一种简单直观的排序算法.它的工作原理如下.首先在未排序序列中找到最小(大)元素,存放到排序序列的起始位置,然后,再从剩余未排序元素中继续寻找最小(大)元素,然 ...
- 排序算法 - 选择排序(selection sort)
选择排序(Selection sort)跟插入排序一样,也是O(n^2)的复杂度,这个排序方式也可以用我们的扑克牌来解释. 概念 桌面上有一堆牌,也是杂乱无章的,现在我们想将牌由小到大排序,如果使用选 ...
- 【排序基础】1、选择排序法 - Selection Sort
文章目录 选择排序法 - Selection Sort 为什么要学习O(n^2)的排序算法? 选择排序算法思想 操作:选择排序代码实现 选择排序法 - Selection Sort 简单记录-bobo ...
- 算法Sedgewick第四版-第1章基础-2.1Elementary Sortss-001选择排序法(Selection sort)
一.介绍 1.算法的时间和空间间复杂度 2.特点 Running time is insensitive to input. The process of finding the smallest i ...
- 《算法4》2.1 - 选择排序算法(Selection Sort), Python实现
选择排序算法(Selection Sort)是排序算法的一种初级算法.虽然比较简单,但是基础,理解了有助于后面学习更高深算法,勿以勿小而不为. 排序算法的语言描述: 给定一组物体,根据他们的某种可量化 ...
随机推荐
- Thomas Brinkhoff 基于路网的移动对象生成器的使用[第二版]
Thomas Brinkhoff 基于路网的移动对象生成器的使用 Thomas Brinkhoff 基于路网的移动对象生成器的使用 相关操作的说明 相关文件的说明 运行 导入eclipse后运行时选择 ...
- android 常用库的地址--dialog,recycler
android 弹出框 https://github.com/li-xiaojun/XPopup android RecyclerViewAdapter https://github ...
- Flask 实现登陆 + session
Flask 实现登陆 + session 案例一: # -*- coding: utf-8 -*- # @Time : 2019/9/24 16:26 # @Author : AnWen from f ...
- android AlertDialog控件使用
1.先创建activity_alert_dialog.xml <?xml version="1.0" encoding="utf-8"?> < ...
- [C#(WinForm)]判断第一次启动程序
来源:https://bbs.csdn.net/topics/220023353/(10楼) 在判断窗口上添加: string strIsFirstRun = "false"; b ...
- xcode 手动管理内存 的相关知识点总结
一.XCode4.2以后支持自动释放内存ARC xcode自4.2以后就支持自动释放内存了,但有时我们还是想手动管理内存,这如何处理呢. 很简单,想要取消自动释放,只要在 Build Setting ...
- 安装opencv出现的问题
ImportError: DLL load failed***** 1,pip uninstall opencv-python 卸载2,pip install opencv-contrib-pytho ...
- Linux下用的脚本
http://blog.itpub.net/29510932/viewspace-1166603/ 批量启动Tomcat 点击(此处)折叠或打开 #!/bin/bash #JDK路径 export J ...
- 基于django的生成二维码的接口
原理就是在视图层写一个将数据生成二维码的视图函数: def generate_qrcode(request, data): img = qrcode.make(data) buf = BytesIO( ...
- curl-手册
Manual -- curl usage explained Related: Man Page FAQ LATEST VERSION You always find news about wha ...