All pastes #784081 Raw Edit

Quicksort

public java v1 · immutable
·published 2007-11-19 15:10 UTC
rendered paste body
         /**	 * Sort the array A by performing quicksort.	 * 	 * @param A The array to be sorted.	 */	public void sort( int[] A )	{		quickSort(A, 0,A.length-1);	}	/**	 * 	 * This Method consists of a divide step: partition	 * and a conquer step: recursive calls to quickSort	 * on the partitioned array.	 * 	 * @param A Array	 * @param left Left border	 * @param right Right border	 */	private void quickSort( int [] A, int left, int right ) 	{		reccount ++;				if(left < right){			int q = partition(A,left,right);			quickSort(A, left, q-1);			quickSort(A, q+1, right);		}	}private int getPivotIndex( int[] A, int left, int right ) 	{		switch (pivotType){					case MIDPOINT:				//System.out.println("Auswahl des Pivotelement ueber Mittelpunkt des Array's ");				return A.length/2;											case RANDOMLY:					//System.out.println("Auswahl des Pivotelement ueber Random ");				return getRandom(left, right);											case MEDIAN_OF_3:				//System.out.println("Auswahl des Pivotelement ueber MEDIAN_OF_3 ");				return (A[left]+A[right]+A[right/2])/3;											case LEFTBORDER:				//System.out.println("Auswahl des Pivotelement ueber Leftboarder ");				return left;										case RIGHTBORDER:				//System.out.println("Auswahl des Pivotelement ueber Rightboarder ");								return  right;							default:				//System.out.println("Keine Methode ausgewählt:");				return 0;							}	}