) 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

最新文章

  1. (原)3.1 Zookeeper应用 - Master选举
  2. Linux下使用Eclipse开发Hadoop应用程序
  3. php获取一维,二维数组长度的方法(有实例)
  4. &#39;Could not load NIB in bundle: &#39;NSBundle xxx/storeFlix.app&gt; &#39; with name &#39;UIViewController-w6Q-ra-j06&#39; and directory &#39;StoreFlixIpad.storyboardc
  5. loadrunner 联机跑负载 win server 2012 r2环境部署
  6. jQuery中的事件冒泡
  7. 【高级功能】使用canvas元素(第二部分)
  8. Java Annotation原理分析(一)
  9. jQuery骨架
  10. sparkSQL1.1入门
  11. 深入理解计算机系统第二版习题解答CSAPP 2.8
  12. 关于json文本数据的一些使用方法
  13. 基于PHP的crontab定时任务管理
  14. 设计模式(二)-- 外观模式(Facade)
  15. Linux 实例常用内核网络参数介绍与常见问题处理
  16. [dev][ipsec][dpdk] strongswan/dpdk源码分析之ipsec算法配置过程
  17. forms组件
  18. 初识css预处理器:Sass、LESS
  19. jquery ajax 中实现给变量赋值
  20. Employee类

热门文章

  1. Mybatis JPA-集成方案+源码
  2. 一个很easy的脚本--php获取服务器端的相关信息
  3. Django之视图系统
  4. linux部署MantisBT(一)部署apache
  5. mongodb windows 4 zip安装
  6. USACO 1.5.4 Checker Challenge跳棋的挑战(回溯法求解N皇后问题+八皇后问题说明)
  7. 食物链 POJ 1182(种类并查集)
  8. python 抓取网页(一)
  9. 软件工程-东北师大站-第五次作业(PSP)
  10. c# 消息机制