惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Attack and Defense Labs
Attack and Defense Labs
The GitHub Blog
The GitHub Blog
C
Check Point Blog
博客园_首页
MongoDB | Blog
MongoDB | Blog
N
Netflix TechBlog - Medium
F
Full Disclosure
Microsoft Security Blog
Microsoft Security Blog
爱范儿
爱范儿
Recent Announcements
Recent Announcements
阮一峰的网络日志
阮一峰的网络日志
G
GRAHAM CLULEY
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Threat Research - Cisco Blogs
C
Cybersecurity and Infrastructure Security Agency CISA
V
Vulnerabilities – Threatpost
K
Kaspersky official blog
博客园 - 司徒正美
S
Schneier on Security
T
The Exploit Database - CXSecurity.com
Project Zero
Project Zero
云风的 BLOG
云风的 BLOG
Cisco Talos Blog
Cisco Talos Blog
Know Your Adversary
Know Your Adversary
雷峰网
雷峰网
V
V2EX - 技术
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Spread Privacy
Spread Privacy
罗磊的独立博客
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Security Affairs
SecWiki News
SecWiki News
Schneier on Security
Schneier on Security
O
OpenAI News
Jina AI
Jina AI
PCI Perspectives
PCI Perspectives
Cyberwarzone
Cyberwarzone
Y
Y Combinator Blog
Apple Machine Learning Research
Apple Machine Learning Research
B
Blog RSS Feed
I
InfoQ
D
Docker
P
Palo Alto Networks Blog
Recorded Future
Recorded Future
M
MIT News - Artificial intelligence
博客园 - Franky
B
Blog
Scott Helme
Scott Helme
博客园 - 叶小钗
D
DataBreaches.Net

博客园 - 方寸心间

改进的前序遍历树模型(The Nested Set Model) Strtus2 Convention Plugin - 方寸心间 hibernate3.2由hbm文件生成pojo和ddl 【转】关于Hibernate的unsaved-value 【转】IntelliJ IDEA使用技巧一览表 【转】maven2完全使用手册 【转】HSQLDB安装与使用 【转】response.setHeader参数、用法的介绍 - 方寸心间 - 博客园 Spring中使用proxool的配置+【转】proxool.xml配置属性说明 [Ubuntu][MySQL]修改MySQL编码 - 方寸心间 [Ubuntu]下安装subversion - 方寸心间 Linux下./configure错误详解 - 方寸心间 【转】CVS使用手册 - 方寸心间 [MySQL]用户密码管理 - 方寸心间 [MySQL]MySql-front连接LINUX平台的MySQL服务 - 方寸心间 [Ubuntu]Apt-get命令参数详解 - 方寸心间 sun jdk,Tomcat在Linux下的安装 - 方寸心间 [Gentoo]中文输入软件Scim的安装【转】 - 方寸心间 [Gentoo]系统时间调整【转】
【转】Java数组排序总结(冒泡,选择,插入,希尔)
方寸心间 · 2008-12-17 · via 博客园 - 方寸心间

public class SortAll {   
  
 
/**  
  * 冒泡排序,选择排序,插入排序,希尔(Shell)排序 Java的实现   
  * 2008.11.09  
  * 
@author YangL. (http://www.idcn.org)  
  
*/  
 
public static void main(String[] args) {   
  
int[] i = { 15612493233940359687 };   
  System.out.println(
"----冒泡排序的结果:");   
  maoPao(i);   
  System.out.println();   
  System.out.println(
"----选择排序的结果:");   
  xuanZe(i);   
  System.out.println();   
  System.out.println(
"----插入排序的结果:");   
  chaRu(i);   
  System.out.println();   
  System.out.println(
"----希尔(Shell)排序的结果:");   
  shell(i);   
 }   
  
 
// 冒泡排序   
 public static void maoPao(int[] x) {   
  
for (int i = 0; i < x.length; i++) {   
   
for (int j = i + 1; j < x.length; j++) {   
    
if (x[i] > x[j]) {   
     
int temp = x[i];   
     x[i] 
= x[j];   
     x[j] 
= temp;   
    }   
   }   
  }   
  
for (int i : x) {   
   System.out.print(i 
+ " ");   
  }   
 }   
  
 
// 选择排序   
 public static void xuanZe(int[] x) {   
  
for (int i = 0; i < x.length; i++) {   
   
int lowerIndex = i;   
   
// 找出最小的一个索引   
   for (int j = i + 1; j < x.length; j++) {   
    
if (x[j] < x[lowerIndex]) {   
     lowerIndex 
= j;   
    }   
   }   
   
// 交换   
   int temp = x[i];   
   x[i] 
= x[lowerIndex];   
   x[lowerIndex] 
= temp;   
  }   
  
for (int i : x) {   
   System.out.print(i 
+ " ");   
  }   
 }   
  
 
// 插入排序   
 public static void chaRu(int[] x) {   
  
for (int i = 1; i < x.length; i++) {// i从一开始,因为第一个数已经是排好序的啦   
   for (int j = i; j > 0; j--) {   
    
if (x[j] < x[j - 1]) {   
     
int temp = x[j];   
     x[j] 
= x[j - 1];   
     x[j 
- 1= temp;   
    }   
   }   
  }   
  
for (int i : x) {   
   System.out.print(i 
+ " ");   
  }   
 }   
  
 
// 希尔排序   
 public static void shell(int[] x) {   
  
// 分组   
  for (int increment = x.length / 2; increment > 0; increment /= 2) {   
   
// 每个组内排序   
   for (int i = increment; i < x.length; i++) {   
    
int temp = x[i];   
    
int j = 0;   
    
for (j = i; j >= increment; j -= increment) {   
     
if (temp < x[j - increment]) {   
      x[j] 
= x[j - increment];   
     } 
else {   
      
break;   
     }   
    }   
    x[j] 
= temp;   
   }   
  }   
  
  
for (int i : x) {   
   System.out.print(i 
+ " ");   
  }   
 }   
}