Jump to content

Search a list: Difference between revisions

Line 2,132:
}
CheckIt
</lang>
 
Extra-Extra: Find all occurrences displaying the indexes for each one.
 
<lang M2000 Interpreter>
Module CheckThis {
Inventory Queue Haystack= "foo", "bar", "baz", "quux", "quuux", "quuuux", "bazola", "ztesch", "foo", "bar", "thud", "grunt"
Append Haystack, "foo", "bar", "bletch", "foo", "bar", "fum", "fred", "jim", "sheila", "barney", "flarp", "zxc"
Append Haystack, "spqr", "wombat", "shme", "foo", "bar", "baz", "bongo", "spam", "eggs", "snork", "foo", "bar"
Append Haystack, "zot", "blarg", "wibble", "toto", "titi", "tata", "tutu", "pippo", "pluto", "paperino", "aap"
Append Haystack, "noot", "mies", "oogle", "foogle", "boogle", "zork", "gork", "bork"
\\ Print all list
Print Haystack
\\ inventory queue can get same keys
\\ inventory use hashtable.
\\ Inventory put same keys in a linked list, so we can found easy
Do
Input "Word to search for? (Leave blank press enter to exit) ", needle$
if needle$="" then exit
n=1
s$=lcase$(needle$)
While exist(Haystack, s$, n)
\\ number, key and position (zero based convert to one based)
Print n, Eval$(HayStack!), Eval(HayStack!)+1
n++
End While
If n=1 Then Print needle$;" not found"
Always
}
CheckThis
</lang>
 
404

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.