retroforth/example/sort-on-stack.retro
crc 848ba7303b use .retro instead of .forth in examples
FossilOrigin-Name: b5feea667d30aac255d1cfca61fed355d438d2ce6021677f1e53af6302b15eee
2019-08-20 18:46:40 +00:00

14 lines
338 B
Forth

# Sorting Numbers on the Stack
This is a recursive approach to sorting values on the stack. I
won't try to claim that this is efficient, but it works.
~~~
:sort-pair dup-pair lt? &swap if ;
:perform-sort sort-pair depth #2 gt? [ &perform-sort dip ] if ;
:sort depth &perform-sort times ;
~~~
```
#3 #33 #22 #333 #5 sort
```