Created
May 20, 2017 19:39
-
-
Save andrewsouthard1/3a16607c175cad895d7cb8000b629e97 to your computer and use it in GitHub Desktop.
Quicksort pseudocode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while i < last | |
pivot = myArray[last] — 4 | |
myArray = [3, 4, 1, 5, 7, 1, 4] | |
i = 0 | |
p_index = 0 | |
myArray = [3, 4, 1, 5, 7, 1, 4] | |
arr[i] = 3 is less than or equal to 4, | |
3 will stay in its position(swapping 0 with 0) | |
i = 1 | |
p_index = 1 | |
myArray = [3, 4, 1, 5, 7, 1, 4] | |
4 is less than or equal to 4 | |
swap (1 with 1) | |
i = 2 | |
p_index = 2 | |
myArray = [3, 4, 1, 5, 7, 1, 4] | |
1 is less than or equal to 4 | |
swap (2 with 2) | |
i = 3 | |
p_index = 3 | |
myArray = [3, 4, 1, 5, 7, 1, 4] | |
5 is greater than 4 | |
do not swap | |
i = 4 | |
p_index = 3 | |
myArray = [3, 4, 1, 5, 7, 1, 4] | |
7 is greater than 4 | |
do not swap | |
i = 5 | |
p_index = 3 | |
myArray = [3, 4, 1, 5, 7, 1, 4] | |
1 is less than or equal to 4 | |
swap element at arr[i] 1 with element at arr[p_index] 5 | |
i = 6 | |
p_index = 4 | |
myArray = [3, 4, 1, 1, 7, 5, 4] | |
i is not less than last | |
p_index = 4 | |
swap element at arr[pivot] with element at p[index] | |
myArray = [3, 4, 1, 1, 4, 5, 7] | |
end | |
return p_index = 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment