On Saturday, September 2, 2023 at 9:51:16 PM UTC+2, Bob Armstrong wrote:
> It's been too long since I checked comp.lang.forth . comp.lang.apl has too little activity to bother with & I didn't realize that is far from true here .
>
> Anybody got a good ` sort algorithm ?
I got plenty. They come in two flavors, address based and index based. The address based ones work with any structure, as long as they exist as pointer arrays. The comparison uses a call back function:
Algorithm Library
Slow sort slowsort.4th
Stooge sort stoosort.4th
Cycle sort cyclsort.4th
Pancake sort pancsort.4th
Radix sort LSB radxsort.4th
Bubble sort bublsort.4th
Cocktail sort cocksort.4th
Cocktail sort
(improved) coc2sort.4th
Simple sort simpsort.4th
Simple sort
(improved) ismpsort.4th
Selection sort selcsort.4th
Insertion sort instsort.4th
Insertion sort
(improved) ins2sort.4th
Binary Insertion sort binssort.4th
Oyelami sort (MDIS) oyelsort.4th
Circle sort circsort.4th
Circle sort (improved) cir2sort.4th
Bitonic sort bitosort.4th
Merge sort mergsort.4th
Odd-even merge sort odevsort.4th
Tim sort (simple) timsort.4th
Shell sort shelsort.4th
Shell sort (A033622) shelsort.4th
Shell sort (A108870) shelsort.4th
Comb sort com2sort.4th
Heap sort hea2sort.4th
Binary Quick sort binquick.4th
Intro sort intrsort.4th
Quick sort qsort.4th
Quick sort
(unsafe) qsort.4th
The index based ones work with any structure as well, as long as they're random accessible (by using an index). Both the compare and the exchange words are callbacks:
Algorithm Library
Heap sort heapsort.4th
Comb sort combsort.4th
Selection sort sel2sort.4th
Bubble sort bub2sort.4th
Gnome sort gnomsort.4th
Gnome sort (improved) gno2sort.4th
They're written for 4tH, so some assembly may be required. You can find them here:
https://sourceforge.net/p/forth-4th/code/HEAD/tree/trunk/4th.src/lib/
Hans Bezemer