Created
April 18, 2011 02:06
-
-
Save eiiches/924692 to your computer and use it in GitHub Desktop.
Quicksort in Bash
This file contains 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
#!/bin/bash | |
filter () { | |
f="$1"; shift | |
for e in "$@"; do | |
if $f "$e"; then | |
echo -n "$e " | |
fi | |
done | |
} | |
qsort () { | |
if [ $# -gt 1 ]; then | |
p="$1"; shift | |
qsort $(filter "test $p -lt" "$@") | |
echo -n "$p " | |
qsort $(filter "test $p -ge" "$@") | |
elif [ $# -eq 1 ]; then | |
echo -n "$1 " | |
fi | |
} | |
qsort 10 3 5 2 20 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it doesnt work for more than 6 numbers