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. 关于Reapter多重嵌套的详细补充

    <asp:Repeater ID ="rptfour" runat ="server" OnItemDataBound="two_Bind&qu ...

  2. 什么是J2EE,包括哪些规范!

    J2EE平台由一整套服务(Services).应用程序接口(APIs)和协议构成,它对开发基于Web的多层应用提供了功能支持,下面对J2EE中的13种技术规范进行简单的描述(限于篇幅,这里只能进行简单 ...

  3. Qt5.4 VS2010 Additional Dependancies

    Go to Linker -> General -> Additional LIbrary Directories: qtmaind.libQt5Cored.libQt5Guid.libQ ...

  4. 关于isset使用产生Can't use function return value in write context错误

    在使用isset检测session的一个取值是否存在时,产生了这个问题 翻译一下:不能在填写的内容中使用函数的返回值.然后我查看了php手册看isset函数的使用:isset()只能用于变量,因为传递 ...

  5. php读取3389脚本

    <?php $regkey = 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\Wds\rdpwd\Td ...

  6. Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.5:compile

    mvn clean mvn install mvn clean -Dmaven.test.skip=true install 出现上述问题,找不到很多类的一些方法. 解决方法: 1.Window -- ...

  7. flowvisor test(1)

    参考: Flowvisor 入门 杨帅老师:mininet+FlowVisor+ODL环境搭建及实验1 安装: 参考: 1.Flowvisor安装 2.Mininet安装 3.官网,Floodligh ...

  8. a computer-centered view of information systems to a database-centered view

    Code.Complete.Second.Edition 2004 Bachman compared the Ptolemaic-to-Copernican change in astronomy t ...

  9. __LINE__ check_arr_empty($arr)

    <?php $arr = array('','',''); foreach($arr as $w) { // w(empty($w)); } w(empty($arr)); w(check_ar ...

  10. JAVA中的throws和throw的区别

    Java     一直对java中的throws和throw不太理解.最近一直在查这两个方面的资料,算是能明白一点吧.如果我下面的观点哪有不对,希望指出来,我加以改进.         throw:( ...