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. [转载] #define new DEBUG_NEW

    在用vc时,利用AppWizard会产生如下代码: #ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] ...

  2. sql语句清除mssql日志

    DUMP TRANSACTION TestDB WITH NO_LOG 清除日志 DBCC SHRINKFILE ('TestDB_log',1) 收缩数据库文件            -----直接 ...

  3. Grunt - grunt-contrib-connect

    快速搭建本地化服务 推荐加强版 : http://www.cnblogs.com/CyLee/p/5331055.html 首先要安装全局的grunt-cli sudo npm install gru ...

  4. mysqld服务器如何查看使用变量的值

    你能用这个命令得到mysqld服务器缺省缓冲区大小: shell> mysqld --help 这个命令生成一张所有mysqld选项和可配置变量的表.输出包括缺省值并且看上去象这样一些东西: P ...

  5. PowerShell监控Windows打印服务器

    转自:http://sodaxu.blog.51cto.com/8850288/1417385 #获取日志,事件ID 307即我们需要提取的事件. path后的路径要与operational日志属性里 ...

  6. 字符串&数组的相互转换

    字符串 -> 数组 方法一: $str = "abcd" $s2 = $str.GetEnumerator()  #$s2是无法使用下标的方式进行索引的,因为其不是array ...

  7. css实现文字过长省略显示

    .simpleName { width:110px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; } <div cl ...

  8. typecho流程原理和插件机制浅析(第二弹)

    typecho流程原理和插件机制浅析(第二弹) 兜兜 393 2014年04月02日 发布 推荐 1 推荐 收藏 14 收藏,3.7k 浏览 上一次说了 Typecho 大致的流程,今天简单说一下插件 ...

  9. http UserAgent

    string uAgent = Request.ServerVariables["HTTP_USER_AGENT"].ToLower();  //获取客户端浏览器的请求 判断 是什 ...

  10. spotlight监控工具使用

    利用spotlight工具可以监控如下系统:        1.Spotlight on Unix 监控Linux服务器 1)安装 Spotlight on Unix 2)配置spotlight登陆用 ...