39f995a3b4
FossilOrigin-Name: a87d738bdda655512aee7a836a49439bc71a716db99ce3722ad2d2a5cec834e3
14 lines
338 B
Forth
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
|
|
```
|