Sort Integers
2024-08-22 17:27:29
) algorithm.
分析
bubble sort
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
public class Solution { /** * @param A an integer array * @return void */ public void sortIntegers( int [] A) { // Write your code here for ( int i = 0 ; i < A.length - 1 ; ++i){ for ( int j = 0 ; j < A.length - i - 1 ; ++j){ if ( A[j] > A[j+ 1 ]) swap(A, j, j+ 1 ); } } } public void swap( int [] A, int i, int j){ int tmp = A[i]; A[i] = A[j]; A[j] = tmp; } } |
selection sort
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
public class Solution { /** * @param A an integer array * @return void */ public void sortIntegers( int [] A) { // Write your code here for ( int i = 0 ; i < A.length; ++i){ int min_i = i; for ( int j = i; j < A.length; ++j){ if (A[min_i] >= A[j]) min_i = j; } swap(A, i, min_i); } } public void swap( int [] A, int i, int j){ int tmp = A[i]; A[i] = A[j]; A[j] = tmp; } } |
insert sort
最新文章
- (原)3.1 Zookeeper应用 - Master选举
- Linux下使用Eclipse开发Hadoop应用程序
- php获取一维,二维数组长度的方法(有实例)
- &#39;Could not load NIB in bundle: &#39;NSBundle xxx/storeFlix.app>; &#39; with name &#39;UIViewController-w6Q-ra-j06&#39; and directory &#39;StoreFlixIpad.storyboardc
- loadrunner 联机跑负载 win server 2012 r2环境部署
- jQuery中的事件冒泡
- 【高级功能】使用canvas元素(第二部分)
- Java Annotation原理分析(一)
- jQuery骨架
- sparkSQL1.1入门
- 深入理解计算机系统第二版习题解答CSAPP 2.8
- 关于json文本数据的一些使用方法
- 基于PHP的crontab定时任务管理
- 设计模式(二)-- 外观模式(Facade)
- Linux 实例常用内核网络参数介绍与常见问题处理
- [dev][ipsec][dpdk] strongswan/dpdk源码分析之ipsec算法配置过程
- forms组件
- 初识css预处理器:Sass、LESS
- jquery ajax 中实现给变量赋值
- Employee类