以下陈述的解释是什么? [英] What is the explaination of the below statements
本文介绍了以下陈述的解释是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
class Node
{
int data;
Node root,left, right;
public Node(int item)
{
data = item;
left = right = null;
}
root.left=null;
}
我是java的初学者,我无法理解这段代码。 Node是一个类,Node()是用于赋值的构造函数。什么是Node root,左边是什么意思?什么是root.left意味着什么?我应该学习哪个概念来理解这个?如果我们创建root作为对象意味着我必须使用new关键字,但这里的代码没有Node root = new Node();.
我尝试了什么:
我试过引用一些资源,但我无法理解这一点。任何人都可以帮忙。
I am beginner to java and I am unable to understand this code. Node is a class and Node() is constructor for assigning value. What is Node root,left mean? And what is root.left means? Which concept i should learn to understand this? If we are creating root as object means I have to use "new" keyword but here the code do not have Node root=new Node();.
What I have tried:
I tried referring some resources but I am unable to understand this. Can anyone please help.
推荐答案
OK - Node是一个类,正如你所说,Node()是该类的构造函数,它接受一个整数参数。
此代码不会创建节点
的实例 - 这是 执行时执行的代码 使用new
关键字创建一个实例。
它的含义是Node类的data
元素,它保存节点的值,以及三个对其他节点
的引用:root
,左
,右
- 以及最初创建节点时
,左
和右
不要去任何地方所以他们总是设置为null
表示。
当您使用多个Node
实例时,构建一个二进制文件树,您将填写根
,左
和正确
适当地形成实际的树st结构本身。
返回并重新阅读你的笔记:这一切都已经解释过了!
OK - Node is a class, and as you say, Node() is a constructor of that class, which takes an integer parameter.
This code doesn't create an instance of aNode
- it's the code that is executed when you do create an instance by using thenew
keyword.
What it's saying is that the Node class has adata
element, which holds the value for the node, and three references to otherNode
s:root
,left
, andright
- and when you initially create theNode
,left
andright
don't "go anywhere" so they are always set tonull
to indicate that.
When you use a number ofNode
instances build a binary tree, you will "fill in" theroot
,left
, andright
appropriately to form the actual tree structure itself.
Go back and re-read your notes: this should all have been explained!
这篇关于以下陈述的解释是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文