插入排序(INSERTION-SORT)
来源:互联网 发布:怎样软件编写 编辑:程序博客网 时间:2024/06/05 18:35
/** * INSERTION-SORT(A) * for j = 2 to A.length * key = A[j] * //Insert A[j] into the sorted sequence A[1..j-1]. * i = j - 1 * while i>0 and A[i] > key * A[i+1] = A[i] * i = i-1 * A[i+1] = key * * */public class InsertSort {public static void main(String[] args) {// TODO Auto-generated method stubList<Integer> raw = new ArrayList<Integer>();raw.add(5);raw.add(2);raw.add(4);raw.add(6);raw.add(1);raw.add(3);int rawLength = raw.size();for(int i = 1; i < rawLength; i++){int current = raw.get(i);int j = i-1;while(j>=0 && raw.get(j)>current){raw.set(j+1, raw.get(j));j--;}raw.set(j+1, current);}for(int r : raw){System.out.println(r);}}}
阅读全文
0 0
- 插入排序(insertion sort)
- insertion sort 插入排序
- 插入排序(Insertion Sort)
- 插入排序 Insertion Sort
- 插入排序Insertion sort
- 插入排序 (Insertion Sort)
- 插入排序Insertion sort
- 插入排序 Insertion Sort
- 插入排序 insertion sort
- 插入排序 insertion sort
- 插入排序Insertion sort
- 插入排序 Insertion sort
- 插入排序 Insertion Sort
- 插入排序-----Insertion Sort
- INSERTION-SORT插入排序
- 插入排序Insertion Sort
- insertion sort(插入排序)
- 插入排序-Insertion sort
- 支付宝-APP支付接入
- eclipse项目轻松导入AndroidStudio
- Build path specifies execution environment JavaSE-1.5 警告的解决办法
- git使用笔记(从远程库clone)
- Java反射
- 插入排序(INSERTION-SORT)
- 通过Stack实现加减乘除
- PAT (Advanced Level) Practise 1066 Root of AVL Tree (25)
- chrom安装插件
- 关于i++和++i的辨别
- Python学习笔记——利用Python统计某目录下所有文本中内容行数
- setjmp()和longjmp()函数详解
- AngularJS第三课(控制器(续),过滤器,服务)
- TTEFS_User 用户模式透明加密开发控件