Last active
March 26, 2022 21:07
-
-
Save xnoreq/8ec07041f26cf6de8471013c7a526896 to your computer and use it in GitHub Desktop.
Quicksort in AWK
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
function quicksort(a, left, right, pivot, left_new, right_new) { | |
if (left >= right) return; | |
pivot = a[left + int((right - left) / 2)]; | |
left_new = left; | |
right_new = right; | |
do { | |
while (a[left_new] < pivot) left_new += 1; | |
while (pivot < a[right_new]) right_new -= 1; | |
if (left_new <= right_new) { | |
tmp=a[left_new]; | |
a[left_new]=a[right_new]; | |
a[right_new]=tmp; | |
left_new++; | |
right_new--; | |
} | |
} while (left_new <= right_new); | |
quicksort(a, left, right_new); | |
quicksort(a, left_new, right); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment