简体   繁体   English

二叉树节点内的节点

[英]Nodes within Binary Tree nodes

I'm currently building a project in which I'm building a binary tree to hold clients which are then required to hold jobs inside of them. 我目前正在构建一个项目,其中正在构建一个二叉树来容纳客户端,然后这些客户端需要在其中保存作业。

I have created a client class which looks like this to be stored in a binary tree: 我创建了一个客户端类,它看起来像这样存储在二进制树中:

public class Client
String givenName;
String surname;

public Client(String givenName, String surname) {
    this.givenName = givenName;
    this.surname = surname;
}

This is just used to store client details. 这仅用于存储客户详细信息。 I also need to use this as a reference for job done for the client. 我还需要将此作为为客户完成的工作的参考。 My job class looks like this: 我的工作类别如下:

public class Job 
Date startTime;
Date finishTime;
String totalTime;
Date date;
String employee;
String notes;
boolean complete;

public Job(Date startTime, Date finishTime, String totalTime, Date date, String employee, String notes, boolean complete) {
    this.startTime = startTime;
    this.finishTime = finishTime;
    this.totalTime = totalTime;
    this.date = date;
    this.employee = employee;
    this.notes = notes;
    this.complete = complete;
}


}

How should I go about making the client classes store the jobs for easy identification and can this be done while the clients are part of a binary tree? 我应该如何使客户端类存储作业以便于识别,并且当客户端是二叉树的一部分时可以做到这一点吗?

It depends on what operations you intend to do with the clients jobs. 这取决于您打算对客户端作业执行哪些操作。 An ArrayList works fine. ArrayList可以正常工作。 If you do many lookups on clients jobs or want to process them in sorted order (by date for example), a HashSet or TreeSet may be better. 如果您在客户端作业上进行了许多查找,或者想按已排序的顺序(例如按日期)进行处理,则HashSet或TreeSet可能更好。

There's no problem in adding jobs to the Client objects. 将作业添加到Client对象没有问题。 The binary tree will contain references to the objects. 二进制树将包含对对象的引用。 If an object is modified, the reference in the binary tree will still point to it. 如果修改了对象,则二叉树中的引用仍将指向该对象。

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

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