数据结构JAVA-----直接插入排序
来源:互联网 发布:幻想降临现实知轩 编辑:程序博客网 时间:2024/06/08 20:01
import java.io.*;
public class Main{
public static void main(String[] args) throws IOException{
int a[]={ 49, 38, 65, 97, 76, 13, 27, 50};
insertSort(a);
for (int i:a) {
System.out.print(i+" ");
}
}
private static void insertSort(int[] a) {
// TODO Auto-generated method stub
int temp;
for (int i = 1; i < a.length; i++) {
for (int j = i; j >0; j--) {
if (a[j]<a[j-1]) {
temp=a[j];
a[j]=a[j-1];
a[j-1]=temp;
}
}
}
}
public class Main{
public static void main(String[] args) throws IOException{
int a[]={ 49, 38, 65, 97, 76, 13, 27, 50};
insertSort(a);
for (int i:a) {
System.out.print(i+" ");
}
}
private static void insertSort(int[] a) {
// TODO Auto-generated method stub
int temp;
for (int i = 1; i < a.length; i++) {
for (int j = i; j >0; j--) {
if (a[j]<a[j-1]) {
temp=a[j];
a[j]=a[j-1];
a[j-1]=temp;
}
}
}
}
}
最好的情况下时间复杂度为O(n),平均为O(n*n),最坏O(n*n),空间复杂度O(1)
阅读全文
0 0
- 数据结构JAVA-----直接插入排序
- {数据结构}直接插入排序
- 数据结构--直接插入排序
- 【数据结构】直接插入排序
- 数据结构---直接插入排序
- 数据结构-直接插入排序
- 数据结构:直接插入排序
- 【数据结构】直接插入排序
- 数据结构----直接插入排序
- 数据结构--直接插入排序
- [数据结构]直接插入排序
- 数据结构---直接插入排序
- 数据结构 直接插入排序
- 数据结构直接插入排序
- java数据结构之插入排序(直接插入排序、折半插入排序、希尔排序)
- 【数据结构】-直接插入排序、希尔排序Java实现
- 数据结构-插入排序-直接插入排序
- 数据结构之直接插入排序
- http请求测试实例(采用fastjson解析)
- 检查型异常(Checked Exception)与非检查型异常(Unchecked Exception)
- 2016蓝桥杯决赛 机器人塔(深搜DFS)
- js基础
- NOIP模拟dp专题 Question 单调栈
- 数据结构JAVA-----直接插入排序
- Python 实现比较文件内容异同
- STL-函数对象适配器
- Markdown新手指南手册
- Unix——optarg与getopt的用法
- Python中常用的模块--Log日志模块
- Android 权限及7.0权限的兼容
- 2017061801公有继承保护继承私有继承公有继承保护继承私有继承
- program files与program files(x86)的区别