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. I am drawing a blank here?
-
4advanced algorithms class???Op De Cirkel– Op De Cirkel2011-06-06 01:09:41 +00:00Commented Jun 6, 2011 at 1:09
-
Are you using java.util.LinkedList or do you have to roll your own for the assignment?Ted Hopp– Ted Hopp2011-06-06 01:10:50 +00:00Commented Jun 6, 2011 at 1:10
-
I am trying to use the built in java.util.LinkedList It was not specified which to use. So I am figuring the Java built in would more than satisfy my needs.allencoded– allencoded2011-06-06 01:31:38 +00:00Commented Jun 6, 2011 at 1:31
Add a comment
|
2 Answers
Create an object that holds a Passenger:
public class Passenger
{
private String name;
private int id;
}
Then give Flight a List of Passengers:
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.