Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ex13_28(a) #113

Open
husy8 opened this issue Apr 9, 2017 · 3 comments
Open

ex13_28(a) #113

husy8 opened this issue Apr 9, 2017 · 3 comments

Comments

@husy8
Copy link
Contributor

husy8 commented Apr 9, 2017

class TreeNode在习题13.28(a)中被定义为:
Exercise 13.28 defines class TreeNode as follow:

class TreeNode {
private:
    std::string value;
    int count;
    TreeNode* left;
    TreeNode* right;
};

但是在 ex13_28.hclass TreeNode却被定义为:
While class TreeNode defined in ex13_28.h is :

class TreeNode {
...
...
...
private:
    std::string value;
    int* count;  // 私有成员 count 类型从 int 变为 int*
                 // Type of private memeber count changed from int to int*
    TreeNode* left;
    TreeNode* right;
};

是当时疏忽了吗?
重新看了一下,感觉这个count是给TreeNode记数的,这样的话,count确实应该是int*类型,可能是书漏印了?

@pezy
Copy link
Owner

pezy commented Apr 9, 2017

重新看了一下,感觉这个count是给TreeNode记数的,这样的话,count确实应该是int*类型,可能是书漏印了?

是的,这道题至今都让我很矛盾。请见:https://www.douban.com/group/topic/71666445/

我的答案给出了我觉得合理的写法。。。

@lnesuper
Copy link

int 还是 int* 这两种定义都是可以的,关键看怎么定义~TreeNode()和拷贝赋值; 当然 int* 的定义是跟着书本走的。最主要保证一点当count变量为0时或者指向的内容为0时析构对象, 拷贝赋值时+1.

@tianlei124
Copy link

会不会有可能是节点序号?序列化的时候需要编号,不过那和本节的内容就不太相关了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants