hasancse91/algorithms

Fetching contributors…
Cannot retrieve contributors at this time
98 lines (79 sloc) 2.23 KB
 #include #include #define MAX 8 int arr[MAX] = {2,7,1,8,6,3,5,4}; void printline(int count) { int i; for(i = 0;i 0 && arr[--rightPointer] > pivot) { //do nothing printf("%d ", arr[rightPointer+1]); } puts(""); if(leftPointer >= rightPointer) { break; } else { printf(" item swapped: a[%d]: %d, a[%d]: %d\n", leftPointer, arr[leftPointer], rightPointer, arr[rightPointer]); swapFunction(leftPointer,rightPointer); //swapFunctionping between [leftPointer] and [rightPointer] } } printf(" pivot swapped :%d,%d\n", arr[leftPointer], arr[right]); swapFunction(leftPointer,right); printf("Updated Array: "); display(); return leftPointer; } void quickSort(int left, int right) { printf("quickSort(%d, %d)\n", left, right); printf("Array is: "); for(int i=left; i<=right; i++) printf("%d ",arr[i]); puts(""); if(right-left <= 0) { return; } else { int pivot = arr[right]; int partitionPoint = partitionFunction(left, right, pivot); printf("partitionFunction Point: %d. Left was: %d, Right was: %d, Pivot: %d\n",partitionPoint, left, right, pivot); quickSort(left,partitionPoint-1); quickSort(partitionPoint+1,right); } } main() { printf("Input Array: "); display(); printline(50); quickSort(0,MAX-1); printf("Output Array: "); display(); printline(50); }