java快速排序

package MSB_Problems;

public class QuickSortMyself {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int[] data = { 2, 3, 1, 5, 22, 45, 12, 34, 11, 0 };
		QuickSort(data, 0, data.length - 1);
		for (int i : data) {
			System.out.print(i + "*");
		}
	}

	private static void QuickSort(int[] data, int low, int high) {
		// TODO Auto-generated method stub
		int i, j, x;
		if (low < high) {
			i = low;
			j = high;
			x = data[i];
			while (i < j) {
				while (i < j && data[j] > x) {
					j--;
				}
				if (i < j) {
					data[i] = data[j];
					i++;
				}
				while (i < j && data[i] < x) {
					i++;
				}
				if (i < j) {
					data[j] = data[i];
					j--;
				}
			}
			data[i] = x;
			QuickSort(data, low, i - 1);
			QuickSort(data, i + 1, high);
		}
	}

}


快速排序比冒泡排序要快,这种方法比较好。

你可能感兴趣的:(java,J#)