Download code

Jump to: navigation, search

Back to Quicksort_(Sed)

Download for Windows: single file, zip

Download for UNIX: single file, zip, tar.gz, tar.bz2

quicksort.sed

 1 #!/usr/bin/sed -f
 2 s/[^0-9]*\([0-9]*\).*/{\1}/
 3 b sort
 4 : part
 5 #   +-1: input before element
 6 #   |         +-2: element to move
 7 #   |         |    +-3: remainder of input
 8 #   |         |    |          +-4: pivot
 9 #   |         |    |          |     +-5: table (codes \2 vs. \4 ordering)
10 #   |         |    |          |     | 
11 s/{\([0-9]*\)\(.\)\([0-9]*\) \(.\) \([0-9]*\2[0-9]*\4[0-9]*\) /{\1\3 \4 \5 \2/
12 t part
13 s/{\([^ ]*\) \(.\) \([^ ]*\) \([^}]*\)}/{\1}\2{\4}/
14 b sort
15 : sort
16 # l
17 s/{}//
18 t sort
19 s/{\(.\)\([^}]*\)}/{\2 \1 9876543210 }/
20 t part
21 


hijacker
hijacker
hijacker
hijacker