初始值失去了! [英] Initialed value lost !

查看:77
本文介绍了初始值失去了!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我正在尝试开发一个压缩后缀trie。

但首先我想让trie工作。

trie的结构就像


class trie {

private:

bool last_node;

map< char,triechildren;


//方法

.....

.....

.....

}

问题是插入一个单词后,

持有的值节点的私有成员(除了root之外)。

insert是一个递归函数

这样添加新节点

trie new_child;

this-> children [alphabet] = new_child;

new_child.insert(word.substr(1)); //再次调用insert。 />
我已经介入调试

这就是发生了什么。我粘贴了这个ppointer的值,并且

数据成员last_node


当我插入第一个waordca


//对于根节点

进入此指针0xbfe254a0

指针0xbfe254a0 0 // last_node为false


已创建另一个节点进入地图并在该节点中设置

将last_node设置为true

this-> last_node = true;


after设置

指针0xbfe25430 1 //最后一个节点设置为true

现在我插入单词cab

根节点很好


输入这个指针0xbfe254a0

指针0xbfe254a0 0


然后根据我去的地图从地图下一个节点(

节点a)。但是后面的last_node成员是假的,即使我有

设置为真之前

指针0xbfe25430 0


谁能说出我做错了什么?

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, triechildren;

//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?

推荐答案

sa ********* @ gmail.com 写道:
sa*********@gmail.com wrote:

你好,

我正在尝试开发一个压缩后缀trie。
Hi there,
I am trying to develop a compressed suffix trie.



只是一个侧节点:它被称为树。

Just a side node: It''s called "tree".


但首先我想要让特里工作。

特里结构就像


class trie {

private:

bool last_node;

map< char,triechildren;


//方法

.... < br $> b $ b ....

....

}

问题是插入一个单词后,由节点的私有成员(除了根目录丢失)所持有的值。

insert是一个递归函数

新节点是像这样添加

trie new_child;
But first I want to get the trie working.
The structure of the trie is like

class trie {
private:
bool last_node;
map<char, triechildren;

//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;



好​​的,所以你创建一个''trie''的本地实例。

Ok, so you create a local instance of ''trie''.


this-> ;儿童[字母] = new_child;
this->children[alphabet]=new_child;



然后将其复制到子地图中。

Then you copy it into your children map.


new_child.insert(word.substr(1 )); //再次调用insert。
new_child.insert(word.substr(1));//insert is called again.



现在你改变了本地对象,它不会影响地图中的副本

。在函数结束时,本地对象和你所做的所有更改将会丢失。

Now you change the local object, which doesn''t affect the copy in your map
at all. At the end of the function, the local object and all the changes
you did to it will be lost.


< a href =mailto:sa ********* @ gmail.com> sa ********* @ gmail.com 写道:
sa*********@gmail.com wrote:

你好,

我正在尝试开发一个压缩后缀trie。


但首先我想让trie工作。

trie的结构就像


class trie {

private:

bool last_node;

map< char,triechildren;


//方法

....

....

....

}

问题是插入一个单词后,
节点的私有成员(除了root之外)。

insert是一个递归函数

新节点像这样添加

trie new_child;
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, triechildren;

//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;



好​​的,所以你创建一个''trie''的本地实例。

Ok, so you create a local instance of ''trie''.


this-> ;儿童[字母] = new_child;
this->children[alphabet]=new_child;



然后将其复制到子地图中。

Then you copy it into your children map.


new_child.insert(word.substr(1 )); //再次调用insert。
new_child.insert(word.substr(1));//insert is called again.



现在你改变了本地对象,它不会影响地图中的副本

。在函数结束时,本地对象和你所做的所有更改将会丢失。

Now you change the local object, which doesn''t affect the copy in your map
at all. At the end of the function, the local object and all the changes
you did to it will be lost.


On 8月9日下午4:11,Rolf Magnus< ramag ... @ t-online.dewrote:
On Aug 9, 4:11 pm, Rolf Magnus <ramag...@t-online.dewrote:

sam.bark ... @ gmail.com写道:
sam.bark...@gmail.com wrote:

你好,

我正在尝试开发一个压缩后缀trie。
Hi there,
I am trying to develop a compressed suffix trie.



只是一个副节点:它被称为树。


Just a side node: It''s called "tree".


但首先我想要让trie工作。

trie的结构就像
But first I want to get the trie working.
The structure of the trie is like


class trie {

私人:

bool last_node;

map< char,triechildren;
class trie {
private:
bool last_node;
map<char, triechildren;


//方法

....

....

....

}

问题是插入一个单词后,

私有成员持有的值节点(除了root之外)。

insert是一个递归函数

这样添加一个新节点

trie new_child;
//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;



好​​的,所以你创建一个''trie''的本地实例。


Ok, so you create a local instance of ''trie''.


this-> ;儿童[字母] = new_child;
this->children[alphabet]=new_child;



然后将其复制到您的子地图中。


Then you copy it into your children map.


new_child.insert(word.substr(1) )); //再次调用insert。
new_child.insert(word.substr(1));//insert is called again.



现在你改变了本地对象,它不会影响地图中的副本

。在函数结束时,本地对象和你所做的所有更改将丢失。


Now you change the local object, which doesn''t affect the copy in your map
at all. At the end of the function, the local object and all the changes
you did to it will be lost.



啊有道理。我以为它是指针。所以如果我

互换线

trie new_child;

new_child.insert(word.substr(1)); //插入是

再次调用。


//插入节点后再连接它

回到父级

this-> children [alphabet] = new_child;

I认为这应该是一个正确的解决方案。如果我错了,请纠正我。

Ah makes sense.I was thinking like it was a pointer.So if I
interchange the lines
trie new_child;
new_child.insert(word.substr(1));//insert is
called again.

//after inserting the nodes then connect it
back to the parent
this->children[alphabet]=new_child;
I think this should be a correct solution.Please correct me if I am
wrong.


这篇关于初始值失去了!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆