简体   繁体   English

如何返回二叉搜索树中最深节点的密钥? (递归)

[英]How to return the key of the deepest node in a binary search tree ? (Recursive)

The key is an int value in a BST. 密钥是BST中的int值。

I've solved a question before that asked for the deepest node size; 在解决了最深的节点大小之前,我已经解决了一个问题。 which wasn't too difficult. 这并不困难。 But I'm not sure how to return the depth to compare for the deepest node and at the same time retrieve the value of the key of that node. 但是我不确定如何返回深度以与最深的节点进行比较,同时获取该节点的键值。 I mean how many return values do you have? 我的意思是您有多少个返回值?

According to this link , you need to declare an object that holds a key value and a depth value. 根据此链接 ,您需要声明一个包含键值和深度值的对象。 Then, you need to return this object. 然后,您需要返回该对象。

As Notrius posted, having a POJO should be simple enough to solve the problem. 正如Notrius所说,拥有POJO应该足够简单以解决问题。 Just for your knowledge, some languages do support the concept of tuples, triplets etc. Java in itself doesn't support this, but there are some simpler libraries to supplement this. 仅就您所知,某些语言确实支持元组,三元组等的概念。Java本身不支持此功能,但是有一些更简单的库可以对此进行补充。 For example, Introduction to Javatuples 例如, Javatuples简介

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM