[英]Java Linked List How to create a node that holds a string and an int?
I have been at this literally all day.我整天都在做这个。 I can create linked lists no problem and display/delete the data in them.
我可以毫无问题地创建链接列表并显示/删除其中的数据。 My problem is though that I am not sure how to create a linked list of flights with each node including a reference to a linked list of passengers?
我的问题是,虽然我不确定如何创建每个节点的航班链接列表,包括对乘客链接列表的引用? This is an assignment in my advanced Algorithms class.
这是我的高级算法 class 中的一个作业。 I am drawing a blank here?
我在这里画一个空白?
Create an object that holds a Passenger:创建一个包含一名乘客的 object:
public class Passenger
{
private String name;
private int id;
}
Then give Flight a List of Passengers:然后给 Flight 一份乘客名单:
public class Flight
{
private List<Passenger> passengers;
}
Now you can have a List of Flights:现在你可以有一个航班列表:
public class Schedule
{
private List<Flight> flights;
}
You needs lots more code in each.你需要更多的代码。 Be sure to override equals and hashCode for Passenger and Flight to make sure that they work properly.
确保覆盖乘客和航班的 equals 和 hashCode 以确保它们正常工作。
Well, can't you just create a Flight
class and a Passenger
class?那么,你不能只创建一个
Flight
class 和一个Passenger
class 吗?
class Flight {
private LinkedList<Passenger> passengers;
...
}
class Passenger {
...
}
LinkedList<Flight> flights = ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.