retroforth/example/sort-on-stack.forth
crc 39f995a3b4 minor updates to examples
FossilOrigin-Name: a87d738bdda655512aee7a836a49439bc71a716db99ce3722ad2d2a5cec834e3
2019-03-29 18:45:44 +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
```