Quicksortを使用して、整数をスタック上のエントリで表されるセット内の要素にソートします。既にソートされている大きな(約10,000要素)セットをソートする必要がある場合を除いて、問題なく動作します。大きなソート配列のForthでの問題
: adswap \ ad1 ad2 --
over @ over @ swap rot ! swap ! ;
: singlepart \ ad1 ad2 -- ad
tuck 2dup @ locals| p ad | swap \ ad2 ad2 ad1
do i @ p < \ ad2 flag
if ad i adswap ad cell + to ad then cell \ ad2 cell
+loop ad adswap ad ; \ ad
: qsort \ ad1 ad2 -- pointing on first and last cell in array
2dup <
if 2dup singlepart >r
swap [email protected] cell - recurse
r> cell + swap recurse
else 2drop
then ;
リターンスタックでオーバーフローすることはありますか。アレイがソートされているかどうかにかかわらず、プログラムがトラックを維持することは事実上不可能です。どうすれば問題を解決できますか?
あなたはruvimありがとう!あなたの助けを借りずにBigZはhttp://forthmath.blogspot.se/で何をしますか? – Lehs