QuickSort

Java Code:

 import java.util.*;
public class quickSort{
public static void main(String [] args){
int [] arr = new int[]{4,2,7,5,0,9,1};
int low = 0;
int high = arr.length-1;
quickSort(arr, low, high);
System.out.println(Arrays.toString(arr));
} private static void quickSort(int [] arr, int low, int high){
if(arr == null || arr.length == 0){
return;
} if(low >= high){
return;
} int pivot = arr[low + (high - low)/2]; //make left < pivot, right > pivot
int i = low;
int j = high;
while(i <= j){
while(arr[i] < pivot){
i++;
}
while(arr[j] > pivot){
j--;
} if(i <= j){
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
i++;
j--;
}
} //recursively sort two sub arrays
quickSort(arr, low, j);
quickSort(arr, i, high);
}
}

Interview Sort Function的更多相关文章

  1. .sort(function(a,b){return a-b});

    var points = [40,100,1,5,25,10]; var b= points.sort(function(a,b){return a-b}); console.log(b); 那个fu ...

  2. [Javascript] Use a custom sort function on an Array in Javascript

    Sorting in Javascript with sort uses lexical sorting by default, which means it will sort in alphabe ...

  3. c++ class as sort function

    // constructing sets #include <iostream> #include <set> #include <string.h> bool f ...

  4. Sort Colors

    Given an array with n objects colored red, white or blue, sort them so that objects of the same colo ...

  5. [LeetCode] Sort Colors 颜色排序

    Given an array with n objects colored red, white or blue, sort them so that objects of the same colo ...

  6. Leetcode 75. Sort Colors

    Given an array with n objects colored red, white or blue, sort them so that objects of the same colo ...

  7. sort()基础知识总结+超简短的英文名排序写法

    结合前些天学的箭头函数我想到一种非常简短的sort排序写法:(这可能是最短的英文名排序方法了) 贴出来大家一起探讨一下: [4,1,2,32].sort((x,y)=>x>y); //[1 ...

  8. js数组的sort排序详解

    <body> <div> sort()对数组排序,不开辟新的内存,对原有数组元素进行调换 </div> <div id="showBox" ...

  9. javascript学习笔记之array.sort

    arrayName.sort()方法: 功能是实现排序(按ascii编码或按数字大小),可无参或有参使用,无参时默认升序排列.有参时可实现升序或降序排列,参数必须是具有返回值的方法,当方法表达式大于0 ...

随机推荐

  1. linux下安装uuid库

    1.linux 下安装UUID库 1.1)ubuntu下安装uuid链接库 sudo apt-get install uuid-dev 1.2)CentOS yum install libuuid-d ...

  2. jBPM4.3+ssh+会签 整合配置及完整实例

    大佬们的项目里有用到会签,所以趁双休日研究了下. 其实也是简单的会签情况,不过开始的时候研究了4.4,(因为先前研究的都是4.4),发现4.4跟4.3的处理方法完全不一样,搞的我比较郁闷……弄了一天, ...

  3. Ubuntu SSH root user cannot login

    Open /etc/ssh/sshd_config and check if PermitRootLogin is set to yes. If not, then set it to yes and ...

  4. 几个与时间相关的php的函数

    这些函数很常用,但是不用的话,像我这样的初学者放下就记不清了,这时最好的办法就是去查文档,写一下印象会更深一些 1.时间戳函数strtotime():一个就是string to time(我自己这样理 ...

  5. 持续集成篇_05_SonarQube代码质量管理平台的介绍与安装

    1.SonarQube的介绍 SonarQube是一个管理代码质量的开放平台. 可以从七个维度检测代码质量(为什么要用SonarQube): (1)复杂度分布(complexity):代码复杂度过高将 ...

  6. jQuery组件系列:封装标签页(Tabs)

    我自己封装的组件,你也行,静态链接地址 http://www.cnblogs.com/leee/p/5190489.html 声明.最好,先把代码拷过去运行一下,其实特别丑~再往下看 我没优化,因为我 ...

  7. Android shell 命令总结

    Package Manage(PM) pm list packages [FILTER] 查看已安装的应用包 -f 显示关联的apk文件 -s 只在系统应用中搜索Filter -3 只在第三方应用中搜 ...

  8. placeholder属性实现text标签默认值提示用户

    <input type="text" class="searchTxt" id=this.id+"-searchTxt" placeh ...

  9. Visual Studio解决方案及项目的配置

    配置解决方案的属性 1.配置解决方案平台,该配置实际上修改的是解决方案目录下的sln(solution)文件. 配置项目的属性 1.配置项目平台及项目的目标平台:项目-右键-属性-生成(竖着第二个选项 ...

  10. oracle case when 语句

    原文:http://www.cnblogs.com/eshizhan/archive/2012/04/06/2435493.html CASE WHEN 表达式有两种形式 简单Case函数 CASE ...