以下陈述的解释是什么? [英] What is the explaination of the below statements

查看:53
本文介绍了以下陈述的解释是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 a Node - it's the code that is executed when you do create an instance by using the new keyword.
What it's saying is that the Node class has a data element, which holds the value for the node, and three references to other Nodes: root, left, and right - and when you initially create the Node, left and right don't "go anywhere" so they are always set to null to indicate that.
When you use a number of Node instances build a binary tree, you will "fill in" the root, left, and right appropriately to form the actual tree structure itself.
Go back and re-read your notes: this should all have been explained!


这篇关于以下陈述的解释是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆