【发布时间】:2014-06-05 22:09:37
【问题描述】:
我创建了一个二叉搜索树节点类。我定义了属性
- 父母
- 左
- 对
- 键
- 价值
我想实现一个二叉搜索树。 isRoot()方法怎么写?
据我所知
public boolean isRoot(){
//return true if it's the root
//return false if it's not
}
parent 已在构造函数中定义,因此无需将其作为参数传递。任何想法如何开始?我知道如何下树,也知道如何上。感谢所有帮助:)
【问题讨论】:
-
类似
return parent == null;? -
如果 parent 为 null 表示根不存在,对吗?
-
我觉得你说的是真的,明白了。
-
如果 parent 为 null,则您是根。首先必须存在一些东西才能运行
isRoot(),所以至少有一个元素。
标签: java methods tree binary-search-tree