排序算法 插入排序
来源:互联网 发布:淘宝上筒子钱真假 编辑:程序博客网 时间:2024/06/17 04:10
package com.sort.test;public class InsertSort {public static void main(String[] args) {int a[] = {49,38,65,97,76,13,27,49,78,34,12,-1,64,5,4,62,99,98,54,56,17,18,23,34,15,35,25,53,51}; ////InsertSort(a);for (int i = 0; i < a.length; i++) {System.out.print(" "+ a[i]);}}/** * 直接插入排序 * * int a[] = {49,38,65,97} * @param array a */public static void InsertSort(int[] a){int temp = 0; for(int i = 1; i< a.length; i++){int j = i-1;// 当i=1 ,时候j = 0 ; temp = a[i];// 把下标1的赋值复给temp ;for(; j>=0 && a[j] > temp ; j--){ // 如果前面的值比后边的大,要重新排一下//将大于temp 的值整体后移一个单位a[j+1] = a[j];}a[j+1] = temp;}}}
阅读全文
0 0
- 排序算法-插入排序
- 排序算法--插入排序
- 排序算法---插入排序
- 排序算法-插入排序
- 排序算法-插入排序
- 排序算法--插入排序
- 排序算法-插入排序
- 排序算法-插入排序
- 排序算法---插入排序
- 排序算法--插入排序
- 排序算法--插入排序
- 排序算法--插入排序
- 排序算法-插入排序
- 排序算法--插入排序
- 排序算法-插入排序
- 排序算法-插入排序
- 排序算法--插入排序
- 排序算法-插入排序
- VS Code 连接 Cocos Creator 调试 launch.json 配置
- spring security 标准Filter及其在filter chain的顺序
- 把二叉树打印成多行
- 解决Eclipse出现卡顿
- aggregations 详解1(概述)
- 排序算法 插入排序
- 《Spring Boot 实战》-- 读书笔记
- weblogic https openssl制作证书及服务器ssl配置
- Synchronized和线程安全
- 移动端focus事件失效问题
- Git可视化教程——Git Gui的使用
- 2017/9/22工作总结
- java中的异常和IO流
- “工欲善其事 必先利其器”