用java实现的快速排序
来源:互联网 发布:北大光华知乎 编辑:程序博客网 时间:2024/05/23 13:56
package com.phj.math;
public class QuickSort {
public static void main(String[] args) {
Quick qs = new Quick();
int data[] = { 44, 22, 2, 32, 54, 22, 88, 77, 99, 11 };
qs.data = data;
qs.sort(0, qs.data.length - 1);
qs.display();
}
}
class Quick {
public int[] data = null;
public int partition(int array[], int low, int high) {
int key = array[low];
while (low < high) {
while (low < high && array[high] >= key)
high--;
array[low] = array[high];
while (low < high && array[low] <= key)
low++;
array[high] = array[low];
}
array[low] = key;
return low;
}
public void sort(int low, int hight) {
if (low < hight) {
int result = partition(data, low, hight);
sort(low, result - 1);
sort(result + 1, hight);
}
}
public void display() {
for (int i = 0; i < data.length; i++) {
System.out.print(data[i] + " ");
}
}
public class QuickSort {
public static void main(String[] args) {
Quick qs = new Quick();
int data[] = { 44, 22, 2, 32, 54, 22, 88, 77, 99, 11 };
qs.data = data;
qs.sort(0, qs.data.length - 1);
qs.display();
}
}
class Quick {
public int[] data = null;
public int partition(int array[], int low, int high) {
int key = array[low];
while (low < high) {
while (low < high && array[high] >= key)
high--;
array[low] = array[high];
while (low < high && array[low] <= key)
low++;
array[high] = array[low];
}
array[low] = key;
return low;
}
public void sort(int low, int hight) {
if (low < hight) {
int result = partition(data, low, hight);
sort(low, result - 1);
sort(result + 1, hight);
}
}
public void display() {
for (int i = 0; i < data.length; i++) {
System.out.print(data[i] + " ");
}
}
}
- 用java实现的快速排序
- 快速排序的JAVA实现
- 快速排序的Java实现
- 快速排序的java实现
- 快速排序的java实现
- 快速排序的java实现
- 快速排序Java的实现
- java实现的快速排序
- 快速排序的JAVA实现
- 快速排序的java实现
- java实现的快速排序
- 快速排序的java实现
- Java 实现的快速排序
- 快速排序的java实现
- 快速排序的java实现
- java 快速排序的实现
- 快速排序的Java实现
- 快速排序的Java实现
- QT框架中快速应用OpenCV——基于视频播放
- 在WIN7下安装phpDocumentor
- System.map
- 折半查找(二分法查找)
- iPhone导航控制器的重要“方法”
- 用java实现的快速排序
- POJ 2388(中位数)
- Qt two ways write Debug() into file
- 根文件系统的挂载过程
- QT openGL 编程 笔记
- 尼玛的百度空间 害我要把文章都转移
- android 获取应用证书及签名信息
- 一个网卡绑定多个IP地址
- JSF+Spring integation