当前位置:网站首页>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]+" ");
}
}
}
边栏推荐
猜你喜欢

Will saffron become a safe and effective natural therapy for patients with arthritis?

Baoli food listed on Shanghai Stock Exchange: annual revenue of 1.578 billion, market value of 5.8 billion

@Simple use of conditional

Set interface

力扣 1480. 一维数组的动态和 383. 赎金信412. Fizz Buzz

面试考点:三种图的问题

Have you understood these 30 questions of enabling financial risk control plus points

JNI程序如何进行参数传递

Background and framework introduction and basic environment preparation of hucang integrated e-commerce project

What should I do if I can't see any tiles on SAP Fiori launchpad?
随机推荐
feign client三个客户端的自动装配
[cute new solution] Fibonacci sequence
Xianghe meat cake in memory
JNI程序如何进行参数传递
ECCV2022 | RU&谷歌提出用CLIP进行zero-shot目标检测!
Overview of static inner classes and non static inner classes
Getting started for beginners: build your own blog with WordPress
592. Fraction addition and subtraction: introduction to expression calculation
flinksql从Oracle同步数据到Doris,一共50几个字段,Oracle表中3000多万条
Gartner 权威预测未来4年网络安全的8大发展趋势
CVPR22 | 关系意识的图神经架构搜索
Detail the construction methods, attributes and common methods in reflection
PG synchronizes multiple data tables to MySQL. Is there a way to simplify the configuration?
Delay queue performance test
聊聊feign组件的一个重要类RefectiveFeign
高度塌陷和BFC
Interview site: three kinds of questions
Musk was exposed to be the founder of Google: he broke up his best friend's second marriage and knelt down to beg for forgiveness
Xshell7 can log in to MySQL virtual machine, but not mysql
轮播图