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

📄 quicksorter.java

📁 A specific version of a quicksorter which can be used to test for efficiveness of different sorts
💻 JAVA
字号:

//
// This class sorts an array using the QuickSort method.

public class QuickSorter
{
	private int[] a;

	public QuickSorter(int[] anArray)
	{
		a=anArray;
	}

	public void sort(int from, int to)
	{
		if (from>=to)
			return;

		int p = partition(from,to);
		sort(from,p);
		sort(p+1,to);
	}

	private int partition(int from, int to)
	{
		int temp;
		int pivot = a[from];
		int i = from-1;
		int j = to +1;

		while(i<j)
		{
			i++;
			while (a[i]<pivot)
				i++;

			j--;

			while(a[j]>pivot)
				j--;

			if(i<j)
			{
				temp = a[i];
				a[i] = a[j];
				a[j] = temp;
			}
		}
		return j;
	}
}

⌨️ 快捷键说明

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