You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
the current pivot loop retests data[b]
each time it moves c. that's needlessly
repeated work. maybe something like
this is better. the comparisons in the
second loop when c == b+1 are also
redundant, but a smaller source of comparisons.
should measure number of comparisons and
do this if it makes sense.
for {
for b < c {
if data.Less(b, pivot) { // data[b] < pivot
b++
} else if !data.Less(pivot, b) { // data[b] = pivot
data.Swap(a, b)
a++
b++
} else {
break
}
}
for b < c {
if data.Less(pivot, c-1) { // data[c-1] > pivot
c--
} else if !data.Less(c-1, pivot) { // data[c-1] = pivot
data.Swap(c-1, d-1)
c--
d--
} else {
break
}
}
if b >= c {
break
}
// data[b] > pivot; data[c-1] < pivot
data.Swap(b, c-1)
b++
c--
}
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: