CODE
Algorithm inPlaceQuickSort(S,a, B ) :
Input: Sequence S of distinct elements; integers a and b
Output: Sequence S with elements originally from ranks from a to b, inclusive,
sorted in nondecreasing order from ranks a to b
if a ? b then return {empty subrange}
p ? S.elemAtRank(B) {pivot}
l ? a {will scan rightward}
r ? b? 1 {will scan leftward}
while l ? r do
{find an element larger than the pivot}
while l ? r and S.elemAtRank(l)? p do
l ? l + 1
{find an element smaller than the pivot}
while r ? l and S.elemAtRank® ? p do
r ? r ? 1
if l < r then
S.swapElements(S.atRank(l),S.atRank®)
{put the pivot into its final place}
S.swapElements(S.atRank(l),S.atRank(B))
{recursive calls}
inPlaceQuickSort(S,a,l ? 1)
inPlaceQuickSort(S,l + 1,B)
Input: Sequence S of distinct elements; integers a and b
Output: Sequence S with elements originally from ranks from a to b, inclusive,
sorted in nondecreasing order from ranks a to b
if a ? b then return {empty subrange}
p ? S.elemAtRank(B) {pivot}
l ? a {will scan rightward}
r ? b? 1 {will scan leftward}
while l ? r do
{find an element larger than the pivot}
while l ? r and S.elemAtRank(l)? p do
l ? l + 1
{find an element smaller than the pivot}
while r ? l and S.elemAtRank® ? p do
r ? r ? 1
if l < r then
S.swapElements(S.atRank(l),S.atRank®)
{put the pivot into its final place}
S.swapElements(S.atRank(l),S.atRank(B))
{recursive calls}
inPlaceQuickSort(S,a,l ? 1)
inPlaceQuickSort(S,l + 1,B)