As part of a programming assignment, I've been asked to implement a suffix trie using C++. We are only allowed to implement this using standard C++11 libraries.
My implementation of the suffix trie consisted of a data structure Trie(string T)
, which constructs a trie for a given string s
. The functions in class Trie
are the following:
Trie::Trie(string T)
- constructor: generates the trie.Trie::substring(string s)
- boolean: checks whether a strings
is a substring ofT
.Trie::suffix(string s)
- boolean: checks whether a strings
is a suffix toT
.Trie::count(string s)
- integer: returns the number of times a substrings
appears throughoutT
(returns 0 if nos
does not occur)Trie::longestRepeat()
- string: finds the longest substring inT
which occurs more than once.Trie::longestSubstring(string S)
- string: finds the longest common substring shared byS
andT
Other relevant information: The Trie
data structure relies on two other data structures - Node
and Edge
. Each Node
has a vector of outgoing_edges
which point to other nodes.
How could I go about implementing an additional function, Trie::show()
which generates a rendition of the trie? Since C++ has no inbuilt graphing libraries, I assume I'm forced to resort to some sort of ASCII-art type function. How could I go about building this, given the functions above?