Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #########################################
- quick sort
- #########################################
- Quicksort(A as array, low as int, high as int){
- if (low < high){
- pivot_location = Partition(A,low,high)
- Quicksort(A,low, pivot_location)
- Quicksort(A, pivot_location + 1, high)
- }
- }
- Partition(A as array, low as int, high as int){
- pivot = A[low]
- leftwall = low
- for i = low + 1 to high{
- if (A[i] < pivot) then{
- swap(A[i], A[leftwall + 1])
- leftwall = leftwall + 1
- }
- }
- swap(pivot,A[leftwall])
- return (leftwall)}
- ######################################
- insertion sort
- ######################################
- INSERTION-SORT(A)
- for j ← 2 to length[A]
- do key ← A[j]
- Insert A[j] into the sorted sequence A[1 j - 1].
- i ← j - 1
- while i > 0 and A[i] > key
- do A[i + 1] ← A[i]
- i ← i - 1
- A[i + 1] ← key
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement