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

📄 testquicksort.java

📁 学算法时写的程序了
💻 JAVA
字号:
package divide;

public class TestQuickSort {
	private static int[] a = {310,285,179,652,351,423,861,254,450,520};
	public static void quickSort(int p,int r) {
		if(p < r) {
			int q = partition(p,r);
			quickSort(p,q-1);
			quickSort(q+1,r);
		}
	}
	
	public static int partition(int p,int r) {
		int i = p;
		int j = r + 1;
		int x = a[p];
		while(true) {
			while(a[i+1]<=x) {i+=1;};
			while(a[j-1]>=x) {j-=1;};
			if(i >= j) break;
			int temp = a[i];
			a[i] = a[j];
			a[j] = temp;
		}
		a[p] = a[j];
		a[j] = x;
		return j;
	}
	
	public static void main(String[] args) {
		
		System.out.println("排序前:");
		for(int temp:a) {
			System.out.print(temp+"  ");
		}
		System.out.println("\n");
		quickSort(0,a.length - 1);
		System.out.println("快速排序后:");
		for(int temp:a) {
			System.out.print(temp+"  ");
		}
	}
}

⌨️ 快捷键说明

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