⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 quicksort.java

📁 QuickSort,SelectSort用Eclipse实现
💻 JAVA
字号:

public class QuickSort {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		for(int i=0;i<a.length;i++){
			System.out.printf("%6d", a[i]);
			}
		sort(a, 0, a.length);
		for(int i=0;i<a.length;i++){
			System.out.printf("%6d", a[i]);
			}
		// TODO Auto-generated method stub

	}
	private static void sort(int[] a,int low,int high)
		{
			if(low<high){
				int pivotloc=Partition(a,low,high);
				sort(a,low,pivotloc-1);
				sort(a,pivotloc+1,high);
				
			}
		}
	private static int Partition(int[] a,int low,int high){
			int pivotkey=a[low];
			while(low<high){
				while(low<high&&a[high]>=pivotkey)--high;
				swap(a,low,high);
				while(low<high&&a[low]<=pivotkey)++low;
				swap(a,low,high);
			}
			return low;
		}
	private static void swap(int[] a,int low,int high){
			int temp=a[low];
			a[low]=a[high];
			a[high]=temp;
		}

static int  []a={12,39,30,83,34,22,68};
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -