本文介绍了父子关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好, 假设我有一个类,这个类有自己类型的属性 例如// 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更多推荐
父子关系
发布评论