summaryrefslogtreecommitdiff
path: root/string/trie.cpp
diff options
context:
space:
mode:
authorPaul Jungeblut <paul.jungeblut@gmail.com>2016-05-24 18:43:52 +0200
committerPaul Jungeblut <paul.jungeblut@gmail.com>2016-05-24 18:43:52 +0200
commitbd927374a755c95eb703aa77eb7f6fe9fe090dc5 (patch)
treeda03fa0b433f5d5454debd2449080a975f940506 /string/trie.cpp
parent66dee0f5f05a135b949910a9156b399c5408ba3b (diff)
String fixes and STL-Debug flag.
Diffstat (limited to 'string/trie.cpp')
-rw-r--r--string/trie.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/string/trie.cpp b/string/trie.cpp
index f4b979c..24a21b2 100644
--- a/string/trie.cpp
+++ b/string/trie.cpp
@@ -1,14 +1,14 @@
-//nur fuer kleinbuchstaben!
+// Implementierung für Kleinbuchstaben.
struct node {
node *(e)[26];
- int c = 0;//anzahl der woerter die an dem node enden.
+ int c = 0; // Anzahl der Wörter, die an diesem node enden.
node() { for(int i = 0; i < 26; i++) e[i] = NULL; }
};
void insert(node *root, string *txt, int s) {
- if(s >= txt->length()) root->c++;
+ if(s == txt->length()) root->c++;
else {
- int idx = (int)((*txt).at(s) - 'a');
+ int idx = (int)(*txt[s] - 'a');
if(root->e[idx] == NULL) {
root->e[idx] = new node();
}
@@ -17,8 +17,8 @@ void insert(node *root, string *txt, int s) {
}
int contains(node *root, string *txt, int s) {
- if(s >= txt->length()) return root->c;
- int idx = (int)((*txt).at(s) - 'a');
+ if(s == txt->length()) return root->c;
+ int idx = (int)(*txt[s] - 'a');
if(root->e[idx] != NULL) {
return contains(root->e[idx], txt, s+1);
} else return 0;