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. X.509证书_生成X.509协议的证书

    用法:1. 用NOTE打开,修改按实际情况脚本中的(1)~ (6)处参数2. 找一台含JVM环境的WIN机器3. 双击执行后,会生成一对密钥4. 请确保当前使用的JDK版本为6.0!!! @echo ...

  2. JS模态窗口返回值兼容问题解决方案

    因系统要兼容原IE已使用的关闭方法,经调试测得,需对window.dialogArguments进行再较验,不然易出问题. function OKEnd(vals) { if (vals == nul ...

  3. PHP统计字符串里单词查询关键字

    <?function full_count_words($str) {     //返回完整数组,包含字符串里每个单词 $words = str_word_count($str,1);     ...

  4. CentOS源列表

    vi /etc/yum.repos.d/CentOS-Base.repo CentOS 5: # CentOS-Base.repo # # The mirror system uses the con ...

  5. php扩展redis,编译安装redis服务

    首先安装redis扩展 https://github.com/phpredis/phpredis 下载http://redis.io/download 服务软件 cd到软件存放目录unzip phpr ...

  6. FastDFS安装、配置、部署

    FastDFS是一个开源的,高性能的的分布式文件系统,他主要的功能包括:文件存储,同步和访问,设计基于高可用和负载均衡,FastDFS非常适用于基于文件服务的站点,例如图片分享和视频分享网站. Fas ...

  7. 【转载】wireshark:no interface can be used for capturing in this system with the current configuration

    转自:wireshark:no interface can be used for capturing in this system with the current configuration 通过 ...

  8. php时间函数time(),date(),mktime()区别

    php时间函数time(),date(),mktime()区别   浏览:1161 发布日期:2014/12/18 分类:系统代码 关键字: php时间函数 time() date()mktime() ...

  9. ESXi云管理平台

    实验室有多台使用ESXi实现虚拟化的服务器,平时管理不便,便通实验室其他同学一起编写了一个基于ESXi的云平台管理系统. 对物理服务器进行管理,实现增加.删除.修改.性能监控. 对虚拟机进行管理,实现 ...

  10. phone number is not known @w@ have no phone, and thus no phone number

    http://dev.mysql.com/doc/refman/5.7/en/problems-with-null.html B.5.4.3 Problems with NULL Values The ...