home *** CD-ROM | disk | FTP | other *** search
- # SORT.TPI
- # by Kent Peterson
- # Recursive sort of values on the stack
- # This routine will sort the stack, placing the smallest
- # items on the top and the largest items on the bottom.
- # Algorithm by Dr. Richard H. Turpin, Purdue University
- # from an article in Forth Dimensions Volume V, No. 2, p 16
-
- defvar flag
-
- define sink
- depth 1 > if over over
- < if swap 0 flag store endif
- push sink pop
- endif
- enddef
-
- define sort
- depth
- do 1 flag store
- sink
- flag fetch if leave endif
- loop
- enddef
-
-
- # now test the sort
- 10 7 15 11 0 -1 24 sort
-
- # and print it out
- depth do print " " print$ loop
-
- begin key until
-
-