advanced sorting notice that the partitioning process doesn' necessarily divide the array in half as it does in this examplethat depends on the pivot value and key values of the data there may be many more items in one group than in the other the partition algorithm the partitioning algorithm works by starting with two pointersone at each end of the array (we use the term pointers to mean indices that point to array elementsnot +pointers the pointer on the leftleftptrmoves toward the rightand the one on the rightrightptrmoves toward the left notice that leftptr and rightptr in the partition java program correspond to leftscan and rightscan in the partition workshop applet actuallyleftptr is initialized to one position to the left of the first celland rightptr to one position to the right of the last cellbecause they will be incremented and decrementedrespectivelybefore they're used stopping and swapping when leftptr encounters data item smaller than the pivot valueit keeps going because that item is already on the correct side of the array howeverwhen it encounters an item larger than the pivot valueit stops similarlywhen rightptr encounters an item larger than the pivotit keeps goingbut when it finds smaller itemit also stops two inner while loopsthe first for leftptr and the second for rightptrcontrol the scanning process pointer stops because its while loop exits here' simplified version of the code that scans for out-of-place itemswhilethearray[++leftptrpivot /(nopwhilethearray[--rightptrpivot /(nopswap(leftptrrightptr)/find bigger item /find smaller item /swap elements the first while loop exits when an item larger than pivot is foundthe second loop exits when an item smaller than pivot is found when both these loops exitboth leftptr and rightptr point to items that are in the wrong sides of the arrayso these items are swapped after the swapthe two pointers continue onagain stopping at items that are in the wrong side of the array and swapping them all this activity is nested in an outer while loopas can be seen in the partitionit(method in listing when the two pointers eventually meetthe partitioning process is complete and this outer while loop exits you can watch the pointers in action when you run the partition workshop applet with bars these pointersrepresented by blue arrowsstart at opposite ends of