@{
\proc{Randomized-Partition}(A, p, r)
\li i = \proc{Random}(p, r)
\li \textup{exchange}\;A[r]\;\textup{and}\;A[i]
\li \Return \proc{Partition}(A, p, r)
}@
\proc{Randomized-Partition}(A, p, r)
\li i = \proc{Random}(p, r)
\li \textup{exchange}\;A[r]\;\textup{and}\;A[i]
\li \Return \proc{Partition}(A, p, r)
}@
@{
\proc{Randomized-Quicksort}(A, p, r)
\li \If p < r
\li \;\;\;\;q = \proc{Randomized-Partition}(A, p, r)
\li \;\;\;\;\proc{Randomized-Quicksort}(A, p, q - 1)
\li \;\;\;\;\proc{Randomized-Quicksort}(A, q + 1, r)
}@
\proc{Randomized-Quicksort}(A, p, r)
\li \If p < r
\li \;\;\;\;q = \proc{Randomized-Partition}(A, p, r)
\li \;\;\;\;\proc{Randomized-Quicksort}(A, p, q - 1)
\li \;\;\;\;\proc{Randomized-Quicksort}(A, q + 1, r)
}@
沒有留言:
張貼留言