Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,39 @@
|
|||
# Project : Move-to-front algorithm
|
||||
|
||||
test("broood")
|
||||
test("bananaaa")
|
||||
test("hiphophiphop")
|
||||
|
||||
func encode(s)
|
||||
symtab = "abcdefghijklmnopqrstuvwxyz"
|
||||
res = ""
|
||||
for i=1 to len(s)
|
||||
ch = s[i]
|
||||
k = substr(symtab, ch)
|
||||
res = res + " " + (k-1)
|
||||
for j=k to 2 step -1
|
||||
symtab[j] = symtab[j-1]
|
||||
next
|
||||
symtab[1] = ch
|
||||
next
|
||||
return res
|
||||
|
||||
func decode(s)
|
||||
s = str2list( substr(s, " ", nl) )
|
||||
symtab = "abcdefghijklmnopqrstuvwxyz"
|
||||
res = ""
|
||||
for i=1 to len(s)
|
||||
k = number(s[i]) + 1
|
||||
ch = symtab[k]
|
||||
res = res + " " + ch
|
||||
for j=k to 2 step -1
|
||||
symtab[j] = symtab[j-1]
|
||||
next
|
||||
symtab[1] = ch
|
||||
next
|
||||
return right(res, len(res)-2)
|
||||
|
||||
func test(s)
|
||||
e = encode(s)
|
||||
d = decode(e)
|
||||
see "" + s + " => " + "(" + right(e, len(e) - 1) + ") " + " => " + substr(d, " ", "") + nl
|
||||
Loading…
Add table
Add a link
Reference in a new issue