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. spark Using MLLib in Scala/Java/Python

    Using MLLib in ScalaFollowing code snippets can be executed in spark-shell. Binary ClassificationThe ...

  2. 离线更新SEPM服务器的病毒定义库

    1. 从http://www.symantec.com/security_response/definitions/download/detail.jsp?gid=sep下载JDB文件    2. 将 ...

  3. 用wget下载文件

    wget使用文档:https://www.gnu.org/software/wget/manual/wget.html 最开始常用的比如: wget -O  /e/movie.mp4 http://w ...

  4. JS实现HTML静态页传值的方法

    JS实现HTML静态页传值的方法 作者:前端开发-武方博 发布:2012-10-29 分类:javascript 阅读:8,735次     此处使用JS方式实现静态页之间值传递,其实很简单,废话不多 ...

  5. Ruby--String

    --全部转为小写:[STR].downcase --全部转为大写:[STR].upcase --仅仅首字母为大写:[STR].capitalize --每个单词首字母为大写:[STR].titleiz ...

  6. UCenter 通信失败 和 无法同步登陆的调试方法

    1. 看请求 2./uc_server/control/admin/app.php echo "\$url = $url <br />\n \$status = $status& ...

  7. 2认识HTML中的“ML”:深入理解超文本

    HTML是描述网页结构的标记语言(即HTML中的'ML'),而HT指把一个网页链接到其他网页. <a>元素可以创建超文本链接到另外一个网页,<a>元素中的内容在网页中是可点击的 ...

  8. java CyclicBarrier

    import java.io.IOException; import java.util.Random; import java.util.concurrent.BrokenBarrierExcept ...

  9. Docker Device Mapper 使用 direct-lvm

      一.Device Mapper: loop-lvm 默认 CentOS7 下 Docker 使用的 Device Mapper 设备默认使用 loopback 设备,后端为自动生成的稀疏文件,如下 ...

  10. TOMCAT源码分析(启动框架)

    建议: 毕竟TOMCAT的框架还是比较复杂的, 单是从文字上理解, 是不那么容易掌握TOMCAT的框架的. 所以得实践.实践.再实践. 建议下载一份TOMCAT的源码, 调试通过, 然后单步跟踪其启动 ...