All pastes #784053 Raw Edit

Quicksort

public java v1 · immutable
·published 2007-11-19 14:47 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);		}	}protected int partition( int[] A, int left, int right ) 	{		/* Als Zeiger wird left und right verwendet*/		int x = A[getPivotIndex(A, left, right)];		int i = left -1 ;				for (int j = left; j< right; j++)		{			comparisons ++;			if (A[j]<=x){				comparisons++;				i++;				swap(A,i,j);			}else								}		swap(A,i+1,right);		return left+1;	}