void Test_Trie() {
   cout << "Started testing Test_Trie()" << endl;
   Trie t;
   t.Push("Airplane");
   t.Push("Aircraft");
   t.Push("Apple");
   t.Push("Zebra");
   t.Push("Air");
   assert(t.Exists("Airplane"));
   assert(t.Exists("Aircraft"));
   assert(t.Exists("Zebra"));
   assert(t.Exists("Human") == false);
   assert(t.Exists("Air"));
   cout << "count match of -Air- : " << t.CountMatches("Air") << endl;
   cout << "count match of -A r- : " << t.CountMatches("A r") << endl;
   cout << "Done testing Test_Trie()" << endl;
}
Exemple #2
0
/*
 * What: Print words in string[]:matrix that exists in Trie:t
 *       Horizonally and vertically
 * How:  For i:length
 *          For j:string.length()
 *             if t.Exists(matrix[i].substring(j, matrix[i].length())
 *                Print
 *
 */
void PrintMatrixWords(const string* matrix, const Trie& t, unsigned length) {
   // Horizonally
   for (unsigned i = 0; i < length; ++i) {
      for (unsigned j = 0; j < matrix[i].length() - 1; ++j) {
         const char* candidate = matrix[i].substr(j).c_str();
         if (t.Exists(candidate)) {
            cout << candidate << endl;
         }
      }
   }
}