after the markers to give [cbasicadajava fortranocamlhaskellpascalsince we obviously cannot have the marker indices 'betweenarray entrieswe will assume the left marker is on the left of [leftmarkand the right marker is to the right of [rightmarkthe markers are therefore 'in the same placeonce rightmark becomes smaller than leftmarkwhich is when we stop if we assume that the keys are integerswe can write the partitioning procedurethat needs to return the final pivot positionaspartition(array aint leftint rightpivotindex choosepivot(aleftrightpivot [pivotindexswap [pivotindexand [rightleftmark left rightmark right while (leftmark <rightmarkwhile (leftmark <rightmark and [leftmark<pivotleftmark+while (leftmark pivotrightmark-if (leftmark rightmarkswap [leftmark++and [rightmark--swap [leftmarkand [rightreturn leftmark this achieves partitioning that ends with the same items in the arraybut in different orderwith all items to the left of the returned pivot position smaller or equal to the pivot valueand all items to the right greater or equal to the pivot value note that this algorithm doesn' require any extra memory it just swaps the items in the original array howeverthe swapping of items means the algorithm is not stable to render quicksort stablethe partitioning must be done in such way that the order of identical items can never be reversed conceptually simple approach that does thisbut requires more memory and copyingis to simply go systematically through the whole arrayre-filling the array with items less than or equal to the pivotand filling second array with items greater or equal to the pivotand finally copying the array into the end of apartition (array aint leftint rightcreate new array of size right-left+ pivotindex choosepivot(aleftrightpivot [pivotindexacount left bcount for left <right +if =pivotindex [ [ielse if [ipivot |( [ =pivot & pivotindex