#!/bin/csh -fv
# fully recursive (see penultimate line) numeric quicksort in the idiot csh
# 	by tchrist@perl.com's evil twin, 18 october 94

enod:
	if ($#argv == 2) 	goto lopo
	set a = `cat`
	echo $a | $0 1 $#a
				goto done
lopo:
	set a = `cat`;
	@ l=$1 r=$2
	if ($r > $l) 		goto node
	echo $a 
				goto done
node:
	@ v = $a[$r] 
	@ i = $l - 1
	@ j = $r
loop:
	@ i ++
	if ($a[$i] < $v ) 	goto loop
opol:
	@ j --
	if ( $a[$j] > $v ) 	goto opol
	if ($i >= $j) 		goto pool
	@ t = $a[$i]
	@ a[$i] = $a[$j]
	@ a[$j] = $t
				goto loop
pool:
	@ t = $a[$i]
	@ a[$i] = $a[$r]
	@ a[$r] = $t
	@ t1 = $i - 1
	@ t2 = $i + 1
	echo $a | $0 $l $t1 | $0 $t2 $r
done:
