0% found this document useful (0 votes)
25 views9 pages

Quick Sort

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPS, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views9 pages

Quick Sort

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPS, PDF, TXT or read online on Scribd
You are on page 1/ 9

Quick Sort

Instructor : Prof. Jyh-Shing Roger


Jang
Designer : Shao-Huan Wang
The ideas are reference to the textbook “Fundamentals of Data Structures in C “ .
Quick Sort
Set an array and add left and right to record the first and last indexes.
Take a pivot key at first term.
Scan from left to right, if the element larger than pivot key,
finding a smaller item from right to left.

lef righ
R0 1 2 3 4 5 6 7 8 9
26 5 37 1 61 11 59 15 48 19 t
0 t9
Quick Sort
Set an array and add left and right to record the first and last indexes.
Take a pivot key at first term.
Scan from left to right, if the element larger than pivot key,
finding a smaller item from right to left.
If j <= i (j : right to left; i : left to right), change the j and pivot key.
Take the left and right array of pivot key to do the same way

lef righ
R0 1 2 3 4 5 6 7 8 9
26 5 19 1 15 11 59 61 48 37 t
0 t9
Quick Sort
Set an array and add left and right to record the first and last indexes.
Take a pivot key at first term.
Scan from left to right, if the element larger than pivot key,
finding a smaller item from right to left.
If j <= i (j : right to left; i : left to right), change the j and pivot key.
Take the left and right array of pivot key to do the same way

lef righ
R0 1 2 3 4 5 6 7 8 9
11 5 19 1 15 26 59 61 48 37 t
0 t9
Quick Sort
Set an array and add left and right to record the first and last indexes.
Take a pivot key at first term.
Scan from left to right, if the element larger than pivot key,
finding a smaller item from right to left.
If j <= i (j : right to left; i : left to right), change the j and pivot key.
Take the left and right array of pivot key to do the same way

lef righ
R0 1 2 3 4 5 6 7 8 9
11 5 19 15 26 59 61 48 37 t
0 t9
1
Quick Sort
Set an array and add left and right to record the first and last indexes.
Take a pivot key at first term.
Scan from left to right, if the element larger than pivot key,
finding a smaller item from right to left.
If j < i (j : right to left; i : left to right), change the j and pivot key.
Take the left and right array of pivot key to do the same way
If j = pivot key, don’t change.

lef righ
R0 1 2 3 4 5 6 7 8 9
5 11 19 15 26 59 61 48 37 t
0 t9
1
Quick Sort
Set an array and add left and right to record the first and last indexes.
Take a pivot key at first term.
Scan from left to right, if the element larger than pivot key,
finding a smaller item from right to left.
If j <= i (j : right to left; i : left to right), change the j and pivot key.
Take the left and right array of pivot key to do the same way
If j = pivot key, don’t change.

lef righ
R0 1 2 3 4 5 6 7 8 9
5 11 19 15 26 59 61 48 37 t
0 t9
1
Quick Sort
Set an array and add left and right to record the first and last indexes.
Take a pivot key at first term.
Scan from left to right, if the element larger than pivot key,
finding a smaller item from right to left.
If j <= i (j : right to left; i : left to right), change the j and pivot key.
Take the left and right array of pivot key to do the same way
If j = pivot key, don’t change.

lef righ
R0 1 2 3 4 5 6 7 8 9
5 11 15 19 26 59 61 48 37 t
0 t9
1
Quick Sort
Set an array and add left and right to record the first and last indexes.
Take a pivot key at first term.
Scan from left to right, if the element larger than pivot key,
finding a smaller item from right to left.
If j <= i (j : right to left; i : left to right), change the j and pivot key.
Take the left and right array of pivot key to do the same way
If j = pivot key, don’t change.

lef righ
R0 1 2 3 4 5 6 7 8 9
5 11 15 19 26 48 37 59 t
0 t9
1 61

You might also like