父子关系

编程入门 行业动态 更新时间:2024-10-26 04:25:27
本文介绍了父子关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好, 假设我有一个类,这个类有自己类型的属性 例如// 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

更多推荐

父子关系

本文发布于:2023-10-25 00:11:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1525386.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:父子   关系

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!