Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- indexing
- author: "Stephen Shaw <shawsd@tcd.ie>"
- description: "Root class for the anagram dictionary program"
- class
- ANAGRAM
- creation
- make
- feature
- anagram_dictionary : ANAGRAM_DICTIONARY
- make is
- local
- input : STRING
- anagrams : HASHED_SET[STRING]
- words : ARRAY[STRING]
- do
- words := << "teals", "stela", "Tesla", "tales", "Stael", "least","tesla", "taels", "stale", "steal", "slate" >>
- create anagram_dictionary.from_array(words)
- io.put_string("Dictionary successfully read%N")
- from
- until
- False
- loop
- io.put_string("Word: ")
- io.read_line
- input := io.last_string
- anagrams := anagram_dictionary.get_anagrams(input)
- show_anagrams(anagrams)
- end
- end -- make
- read_filename : STRING is
- local
- filename : STRING
- do
- io.put_string("Location of dictionary file: ")
- io.read_line
- filename := io.last_string
- rescue
- retry
- end -- read_filename
- show_anagrams(anagrams : HASHED_SET[STRING]) is
- require
- anagrams /= Void
- local
- index : INTEGER
- do
- if anagrams.is_empty then
- io.put_string("Sorry, no anagrams found")
- else
- io.put_integer(anagrams.count)
- io.put_string(" anagrams found:")
- from
- index := anagrams.lower
- until
- index = anagrams.upper
- loop
- io.put_string(anagrams.item(index))
- index := index + 1
- if index < anagrams.upper then
- io.put_string(", ")
- else
- io.put_string(".")
- end
- end
- end
- end -- show_anagrams
- end -- class ANAGRAM
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement