papierkorb:sort_algorithm_in_forth
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| papierkorb:sort_algorithm_in_forth [2025-08-10 21:03] – ↷ Seite von projects:sort_algorithm_in_forth nach papierkorb:sort_algorithm_in_forth verschoben mka | papierkorb:sort_algorithm_in_forth [2026-08-20 15:40] (aktuell) – gelöscht - Externe Bearbeitung (Unbekanntes Datum) 127.0.0.1 | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| - | < | ||
| - | SCR # 21 | ||
| - | 0 ( 16 bit Numerical Sort Demo 20AUG82MIM) | ||
| - | 1 | ||
| - | 2 FORTH DEFINITIONS | ||
| - | 3 7000 CONSTANT ARRAY1 | ||
| - | 4 VARIABLE # | ||
| - | 5 VARIABLE DISTANCE | ||
| - | 6 VARIABLE VI ( temporary indexes for nested DO's) | ||
| - | 7 VARIABLE VJ | ||
| - | 8 VARIABLE SEED HERE SEED ! | ||
| - | 9 | ||
| - | 10 : RND ( random # generator) | ||
| - | | ||
| - | | ||
| - | 13 : CLRS PAGE CR CR 17 SPACES ." FORTH SORTING DEMO" CR ; | ||
| - | 14 : KEYMSG | ||
| - | 15 | ||
| - | |||
| - | |||
| - | |||
| - | SCR # 22 | ||
| - | 0 ( 16 bit Numerical Sort Demo 20AUG82MIM) | ||
| - | 1 | ||
| - | 2 : RANDOM | ||
| - | 3 #ELEMENTS @ 2* 0 ( set loop limit and initial index) | ||
| - | 4 DO 3E8 RND ( fetch random # between 0 and 999) | ||
| - | 5 I 3 MOD 0= IF NEGATE | ||
| - | 6 THEN I ARRAY1 + ! ( store in array) | ||
| - | 7 2 +LOOP ; ( increment loop) | ||
| - | 8 | ||
| - | 9 : REVERSE | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 14 | ||
| - | 15 | ||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | SCR # 23 | ||
| - | 0 ( 16 bit Numerical Sort Demo 20AUG82MIM) | ||
| - | 1 | ||
| - | 2 : NUM(I) @ ARRAY1 + ; ( array fetch) | ||
| - | 3 : NUMI@ NUM(I) @ ; ( and store) | ||
| - | 4 : NUMI! NUM(I) ! ; ( operators) | ||
| - | 5 | ||
| - | 6 : COMPARE VI NUMI@ VJ NUMI@ > ; ( true if #I > #J) | ||
| - | 7 | ||
| - | 8 : NUMSWAP | ||
| - | 9 VI NUMI@ VJ NUMI@ VI NUMI! VJ NUMI! ; | ||
| - | 10 | ||
| - | 11 : NUMLIST | ||
| - | | ||
| - | | ||
| - | | ||
| - | 15 | ||
| - | |||
| - | |||
| - | |||
| - | |||
| - | SCR # 24 | ||
| - | 0 ( 16 bit Numerical Sort Demo 20AUG82MIM) | ||
| - | 1 | ||
| - | 2 : BUBBLESORT | ||
| - | 3 #ELEMENTS @ 1- 2* 0 DO I VI ! | ||
| - | 4 # | ||
| - | 5 COMPARE IF NUMSWAP | ||
| - | 6 THEN 2 +LOOP 2 +LOOP ; | ||
| - | 7 | ||
| - | 8 : SHUTTLESORT | ||
| - | 9 #ELEMENTS @ 1- 2* 0 DO | ||
| - | | ||
| - | | ||
| - | | ||
| - | 13 | ||
| - | 14 ( For decending sorts change > in COMPARE to <) | ||
| - | 15 | ||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | SCR #25 | ||
| - | 0 ( 16 bit Numerical Sort demo 20AUG82MIM) | ||
| - | 1 | ||
| - | 2 : SETDIST | ||
| - | 3 1 BEGIN 2* DUP #ELEMENTS @ > | ||
| - | 4 UNTIL 2- DISTANCE ! ; | ||
| - | 5 | ||
| - | 6 : DECDIST | ||
| - | 7 | ||
| - | 8 | ||
| - | 9 ( Shell-Metzner sort) | ||
| - | 10 : SHELLSORT | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 15 | ||
| - | |||
| - | |||
| - | |||
| - | |||
| - | SCR # 26 | ||
| - | 0 ( 16 bit Numerical Sort Demo 20AUG82MIM) | ||
| - | 1 ( benchmark it) | ||
| - | 2 : # | ||
| - | 3 INTERPRET #ELEMENTS ! ." random array" RANDOM NUMLIST ; | ||
| - | 4 : REVIT CR ." reversed array" REVERSE NUMLIST ; | ||
| - | 5 | ||
| - | 6 : BUBBS #ELEMENTS? ." random bubblesort.." | ||
| - | 7 BUBBLESORT BEEP NUMLIST KEYMSG ." sorting sorted array.." | ||
| - | 8 CR BEEP BUBBLESORT BEEP KEYMSG REVIT | ||
| - | 9 ." reverse bubblesort.." | ||
| - | | ||
| - | 11 : SHUTS #ELEMENTS? ." random shuttlesort.." | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | SCR # 27 | ||
| - | 0 ( 16 bit Numerical Sort Demo 20AUG82MIM) | ||
| - | 1 | ||
| - | 2 : SHELS #ELEMENTS? ." random shellsort.." | ||
| - | 3 SHELLSORT BEEP NUMLIST KEYMSG ." sorting sorted array.." | ||
| - | 4 CR BEEP SHELLSORT BEEP KEYMSG REVIT | ||
| - | 5 ." reverse shellsort.." | ||
| - | 6 NUMLIST KEYMSG ; | ||
| - | 7 : DECODE | ||
| - | 8 DUP 33 = IF SHELS ELSE 34 = IF QUIT THEN THEN THEN THEN ; | ||
| - | 9 : MENU CR CR ." Specify sort algorithm:" | ||
| - | | ||
| - | | ||
| - | | ||
| - | 13 | ||
| - | 14 : DEMO BEGIN CLRS MENU DUP DECODE AGAIN ; | ||
| - | | ||
| - | </ | ||