当前位置:网站首页>插入排序,正序,倒序
插入排序,正序,倒序
2022-07-27 12:48:00 【风间净琉璃】
/**
* 插入排序
* @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);
}
/**
* 正序
* @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]+" ");
}
}
/**
* 倒序
* @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]+" ");
}
}
}
边栏推荐
- POJ1273 Drainage Ditches【最大流】【SAP】
- 关于 CMS 垃圾回收器,你真的懂了吗?
- Multi activity disaster recovery construction after 713 failure of station B | takintalks share
- 正则表达式去除两端空格
- QT | qcheckbox of control
- 详述HashSet的add方法
- Initializing database error after reinstalling MySQL
- Getting started for beginners: build your own blog with WordPress
- 初学者入门:使用WordPress搭建一个专属自己的博客
- 详述throw与throws
猜你喜欢

Overview of famous inner classes and anonymous inner classes

CVPR22 | 关系意识的图神经架构搜索

Mixin\ plug in \scoped style

MySQL extensions

@Simple understanding and use of conditionalonproperty

What should I do if I can't see any tiles on SAP Fiori launchpad?

Map interface

详述throw与throws

Zhongke Lanxun fell 30% on the first day of listing: Huang Zhiqiang, 60, started a company with a market value of 7.7 billion

The sparksubmit. Main () method submits external parameters and remotely submits the standalone cluster task
随机推荐
592. Fraction addition and subtraction: introduction to expression calculation
Isolation level
Cvpr22 | graph neural architecture search of relational consciousness
592. 分数加减运算 : 表达式计算入门题
Will causal learning open the next generation of AI? Chapter 9 Yunji datacanvas officially released the open source project of ylarn causal learning
7-16 daily sword finger offer II 041. Average value of sliding window
Sff1004-mhchxm diode sff1004
nodejs body-parser中间件处理类型 multipart/form-data 的 POST 表单数据,req.body无法接收到数据
写出一个程序,接受一个有字母和数字以及空格组成的字符串,和一个字符,然后输出输入字符串中含有该字符的个数。不区分大小写。
Wfuzz, a test tool that can blur everything that can be blurred
SQL statement problem, calculate the data with a difference of less than 10 minutes to be displayed as the same batch of data
ArrayList常用方法总结
What should I do if I can't see any tiles on SAP Fiori launchpad?
SSM practical project - front back separation (easy to understand)
Security measures for tcp/ip protocol vulnerabilities
Detail the construction methods, attributes and common methods in reflection
文章复现:SRCNN
Mongodb slow query and index
Nodejs body parser middleware processes post form data of type multipart / form data, and req.body cannot receive data
Will saffron become a safe and effective natural therapy for patients with arthritis?