fork(1) download
  1. //my .h file
  2.  
  3. #ifndef __TRIE_H__
  4. #define __TRIE_H__
  5. #include <string>
  6. #include <cctype>
  7.  
  8. struct TrieNode {
  9. enum { Apostrophe = 26, NumChars = 27 };
  10. bool isWord;
  11. char letter;
  12. TrieNode *letters[NumChars];
  13. TrieNode() {
  14. isWord = false;
  15. letter = '/0';
  16. for ( int i = 0; i < NumChars; i += 1 ) {
  17. letters[i] = NULL;
  18. } // for
  19. }
  20. }; // TrieNode
  21.  
  22. void insert( TrieNode &node, const std::string &word );
  23.  
  24.  
  25.  
  26. #endif
  27.  
  28. //my .cpp file
  29.  
  30. #include <iostream>
  31. #include <string>
  32. #include "trie.h"
  33.  
  34. void insert( TrieNode &node, const std::string &word )
  35. {
  36. int x = 0;
  37. while (word[x] != '\0'){
  38. int c = word[x] - 'a';
  39. if ( node.letter[c] == NULL ){
  40. TrieNode *n = new TrieNode();
  41. n->letter = word[i];
  42. n->isWord = false;
  43. for(int i=0;i<26;i++)
  44. {
  45. n->letters[i] = NULL;
  46. }
  47. node.letters[c] = n;
  48. node = n;
  49. }
  50. else { node = node.letters[c]; }
  51. x++;
  52. }
  53. node.isWord = true;
  54. }
  55.  
  56. // my driver
  57. #include <iostream>
  58. #include <iomanip>
  59. #include "trie.h"
  60.  
  61. using namespace std;
  62.  
  63.  
  64. int main()
  65. {
  66. TrieNode x; string line;
  67. cin >> line;
  68. insert(&x,&line);
  69. cout << x.letters[1]->letter;
  70. return 0;
  71. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:15:14: warning: multi-character character constant
prog.cpp:32:18: error: trie.h: No such file or directory
prog.cpp: In constructor ‘TrieNode::TrieNode()’:
prog.cpp:15: warning: overflow in implicit constant conversion
prog.cpp: In function ‘void insert(TrieNode&, const std::string&)’:
prog.cpp:39: error: invalid types ‘char[int]’ for array subscript
prog.cpp:41: error: ‘i’ was not declared in this scope
prog.cpp:48: error: no match for ‘operator=’ in ‘node = n’
prog.cpp:8: note: candidates are: TrieNode& TrieNode::operator=(const TrieNode&)
prog.cpp:50: error: no match for ‘operator=’ in ‘node = node->TrieNode::letters[c]’
prog.cpp:8: note: candidates are: TrieNode& TrieNode::operator=(const TrieNode&)
prog.cpp: In function ‘int main()’:
prog.cpp:68: error: invalid initialization of non-const reference of type ‘TrieNode&’ from a temporary of type ‘TrieNode*’
prog.cpp:34: error: in passing argument 1 of ‘void insert(TrieNode&, const std::string&)’
stdout
Standard output is empty