Anonymous user
Move-to-front algorithm: Difference between revisions
m
→version 2: added/changed whitespace. increased output indentation.
m (added whitespace.) |
m (→version 2: added/changed whitespace. increased output indentation.) |
||
Line 2,131:
<lang rexx>/*REXX program demonstrates the move─to─front algorithm encode/decode symbol table. */
parse arg xxx; if xxx='' then xxx= 'broood bananaaa hiphophiphop' /*use the default?*/
one=
do j=1 for words(xxx);
@= 'abcdefghijklmnopqrstuvwxyz'; @@=
$= /*set the decode string to a null. */
do k=1 for length(x);
_= pos(z, @);
$= $ (_ - one);
end /*k*/ /* [↑] the move─to─front encoding. */
!= /*set the encode string to a null. */
do m=1 for words($);
y= substr(@@, n, 1);
@@= y || delstr(@@, n, 1)
end /*m*/ /* [↑] the move─to─front decoding. */
say ' word: '
end /*j*/ /*stick a fork in it, we're all done. */</lang>
{{out|output|text= when using the default input:}}
<pre>
word: broood encoding: 1 17 15 0 0 5 OK
word: bananaaa encoding: 1 1 13 1 1 1 0 0 OK
word: hiphophiphop encoding: 7 8 15 2 15 2 2 3 2 2 3 2 OK
</pre>
|