简体   繁体   English

Java节点LinkedList

[英]Java Nodes LinkedList

Java Nodes/ LinkedList(Pointer based) the program is basically a node that includes student attributes: Java节点/ LinkedList(基于指针)程序基本上是一个包含学生属性的节点:

first name last name age ID Major 名姓年龄ID专业

There are 3 classes : 1- nodeclass 2- class for the methods (add in the beginning, and add in the end, search etc.. 3 -the test class 有3类:1-节点类2-方法类(在开头添加,在结尾添加,搜索等。)3-测试类

the problem that I'm facing is that I am confused on how to include all the students attributes into one node. 我面临的问题是我对如何将所有学生属性包含到一个节点中感到困惑。

Now an example of the node class(1) to add an integer is: 现在添加一个整数的节点class(1)的示例是:

public class IntNodeF14
{
  int item; 
  IntNodeF14 next;
}

how can I create a node that will accept all the students attributes 我如何创建一个将接受所有学生属性的节点

Make your class generic : 使您的类通用:

public class NodeF14<T>
{
  NodeF14<T> next;
  T data;
}

data would hold the data of a single node. data将保存单个节点的数据。

Then you can create a NodeF14 for any type of data you need. 然后,您可以为NodeF14的任何类型的数据创建一个NodeF14

For example : 例如 :

Student student = new Student (firstName,lastName);
NodeF14<Student> studentNode = new NodeF14<Student> (student);

If you can't use generics, you'll have to include all the properties (or a Student member holding all the properties) in the Node class, but in this case your list will only support one type of data. 如果不能使用泛型,则必须在Node类中包括所有属性(或拥有所有属性的Student成员),但是在这种情况下,您的列表将仅支持一种类型的数据。

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

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