父子关系 [英] parent Child relation

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

问题描述

大家好,

假设我有一个类,这个类有自己类型的属性

例如// node.node。等等



现在我想确定树的深度,因为我创建了一个新属性(int深度)

所以每个新生成的节点,它将有一个深度值= parentdepth + 1;



现在我想知道这个类及其属性之间是否有关系,以便我可以使用对于这份工作,



提前致谢,

z3ngew

解决方案

不要尝试存储深度 - 它可能是错误的,或者会失去步骤并导致问题。如果您需要知道特定节点的深度,请按照它的父列表返回,直到您到达要检查的节点或树的头部。如果你的节点中有一个父属性,这是一个简单的循环 - 如果你不是那么你需要递归检查树,直到你找到节点,或用完节点来检查。


检查此链接:链接

Hello everyone,
Suppose i have a class and this class has a properties of its own type
forexample// node.node. etc

Now i want to identify the depth of my tree, for that i made a new property(int depth)
so that each new generated node it will have a depth value = parentdepth + 1;

Now i want to know is there a relation between the class and its property so that i can use for this job,

Thanks in advance,
z3ngew

解决方案

Don''t try storing a depth - it will either be wrong, or will get out of step and cause problems. If you need to know the depth of a particular node, follow it''s parent list back until you either get to the node you are checking from, or to the head of the tree. It''s a simple loop if you have a parent property in your node - if you don''t then you need to recursively check down the tree until you find the node, or run out of nodes to check.


Check this link: Link


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

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