当前位置:网站首页>Insert sort, positive order, reverse order
Insert sort, positive order, reverse order
2022-07-27 13:22:00 【Clear glaze in the wind】
/**
* Insertion sort
* @author dell
*
*/
public class JinZhiZhuanHuan {
public static void main(String[] args) {
int[] ints ={1,4,2,4,2,3,4543,11,3,6};
ascSort(ints);
System.out.println("");
descSort(ints);
}
/**
* positive sequence
* @param ints
*/
private static void ascSort(int[] ints){
for (int i = 1; i < ints.length; i++) {
if (ints[i] < ints[i - 1]) {
for (int j = i; j > 0; j--) {
int temp = ints[j];
if (ints[j] < ints[j - 1]) {
ints[j] = ints[j - 1];
ints[j - 1] = temp;
}
}
}
}
for (int i = 0; i < ints.length; i++) {
System.out.print(ints[i]+" ");
}
}
/**
* In reverse order
* @param ints
*/
private static void descSort(int[] ints){
for (int i = 1; i < ints.length; i++) {
if (ints[i] > ints[i - 1]) {
for (int j = i; j > 0; j--) {
int temp = ints[j];
if (ints[j] > ints[j - 1]) {
ints[j] = ints[j - 1];
ints[j - 1] = temp;
}
}
}
}
for (int i = 0; i < ints.length; i++) {
System.out.print(ints[i]+" ");
}
}
}
边栏推荐
- Can you tell me the difference between lateinit and lazy in kotlin?
- 完美指南|如何使用 ODBC 进行无代理 Oracle 数据库监控?
- Feign's dynamic proxy
- Feign's overall process
- PG synchronizes multiple data tables to MySQL. Is there a way to simplify the configuration?
- 相对定位
- Method of changing thread state
- heap
- Reptile
- POJ1273 Drainage Ditches【最大流】【SAP】
猜你喜欢

Isolation level

Interface testing practical tutorial 01: interface testing environment construction

Amd adrenalin 22.7.1 driver update: double the performance of OpenGL and support Microsoft win11 22h2 system

Realize the disk partition and file system mount of the newly added hard disk

Qt优秀开源项目之十三:QScintilla

Open source project - taier1.2 release, new workflow, tenant binding simplification and other functions

程序员培训学习后好找工作吗

Set interface

18. Text processing tool -grep

Will saffron become a safe and effective natural therapy for patients with arthritis?
随机推荐
How to get class objects
Pat class B 1109 good at C (detailed)
Xshell7 can log in to MySQL virtual machine, but not mysql
MTK6765编译环境搭建
Interview site: three kinds of questions
Do you really understand CMS garbage collector?
multi-table query
开源项目丨Taier1.2版本发布,新增工作流、租户绑定简化等多项功能
v-on基础指令
Distributed system architecture theory and components
592. 分数加减运算 : 表达式计算入门题
v-text
Xianghe meat cake in memory
500强企业如何提升研发效能?来看看行业专家怎么说!
粘制定位
实现新增加硬盘的磁盘分区和文件系统挂载
Feign的整体流程
图标字体
How to pass parameters in JNI program
Aike AI frontier promotion (7.27)