S
sam.barker0
Hi there,
I am trying to develop a compressed suffix trie.
But first I want to get the trie working.
The structure of the trie is like
class trie {
private:
bool last_node;
map<char, trie> children;
//methods
.....
.....
.....
}
The problem is that after inserting one word,the values held by the
private members of the nodes(other than the root is lost).
insert is a recursive function
new node is added like this
trie new_child;
this->children[alphabet]=new_child;
new_child.insert(word.substr(1));//insert is called again.
I had stepped through to debug
this is what happened.I had a pasteing the value of this ppointer and
the data member last_node
when I insert the first waord "ca"
//for the root node
entering this pointer 0xbfe254a0
pointer 0xbfe254a0 0//last_node is false
the another node is created added into the map and in that node i set
the last_node to true
this->last_node=true;
after setting
pointer 0xbfe25430 1 //last node set to true
now i insert the word "cab"
the root node is fine
entering this pointer 0xbfe254a0
pointer 0xbfe254a0 0
but then from the map based on the letter i go to the next node(to
node a).but then the last_node member is false even though i had
set it true before
pointer 0xbfe25430 0
could anyone tell what I am doing wrong?
I am trying to develop a compressed suffix trie.
But first I want to get the trie working.
The structure of the trie is like
class trie {
private:
bool last_node;
map<char, trie> children;
//methods
.....
.....
.....
}
The problem is that after inserting one word,the values held by the
private members of the nodes(other than the root is lost).
insert is a recursive function
new node is added like this
trie new_child;
this->children[alphabet]=new_child;
new_child.insert(word.substr(1));//insert is called again.
I had stepped through to debug
this is what happened.I had a pasteing the value of this ppointer and
the data member last_node
when I insert the first waord "ca"
//for the root node
entering this pointer 0xbfe254a0
pointer 0xbfe254a0 0//last_node is false
the another node is created added into the map and in that node i set
the last_node to true
this->last_node=true;
after setting
pointer 0xbfe25430 1 //last node set to true
now i insert the word "cab"
the root node is fine
entering this pointer 0xbfe254a0
pointer 0xbfe254a0 0
but then from the map based on the letter i go to the next node(to
node a).but then the last_node member is false even though i had
set it true before
pointer 0xbfe25430 0
could anyone tell what I am doing wrong?