直接插入排序
来源:互联网 发布:数据的力量议论文 编辑:程序博客网 时间:2024/06/05 19:59
直接插入排序:把一个无序的表进行排列成有序顺序的表。每次从无序表中选取第一个元素,插入到有序表中,使得有序表仍然有序。
源码:
package insertsort;
public class InsertSort {
public static void insertSort(int[] array) {
for (int i = 1; i < array.length; i++) {
int j = i;
while (j>=1 && array[j]<array[j - 1]) {
int temp = array[j];
array[j] = array[j - 1];
array[j - 1] = temp;
j--;
}
}
}
public static void main(String[] args) {
int[] testArray = {23, 25, 12, 42, 35};
insertSort(testArray);
System.out.println("The result is:");
for (Integer item : testArray) {
System.out.print(item);
System.out.print(' ');
}
}
}
0 0
- 插入排序--直接插入
- 插入排序------直接插入
- 插入排序---直接插入
- 排序:直接插入排序
- 排序---直接插入排序
- 排序 -- 直接插入排序
- 排序---直接插入排序
- 排序--直接插入排序
- 排序-直接插入排序
- 【排序】直接插入排序
- 排序--直接插入排序
- 排序:直接插入排序
- 【排序】直接插入排序
- 排序--直接插入排序
- 排序--直接插入排序
- 排序-直接插入排序
- 插入排序--直接插入排序
- 插入排序-直接插入排序
- EI Capitan下 CocoaPods命令无法使用问题
- 用DevExpress做界面开发:仿Office的Winforms界面框架
- (八)jms topic与jms queue区别
- JAVA 线程池
- keil V4中,中文注释代码出现乱码解决方法
- 直接插入排序
- 中文域名可以包含哪些字符?
- maven配置servlet
- android网络请求框架 HttpClient与Volley的性能对比
- 用例图
- 优惠券发放接口调优实战
- Marven:使用Maven构建Java项目
- (九)JMS的两种消息模型(Point-to-Point(P2P)和Publish/Subscribe(Pub/Sub))应用举例
- code_templates.xml