-
Queuing Nodes
I am trying to make a basic program for an Air traffic controller to land planes as the come in using nodes but i cant get the nodes to order properly as when i add a new one in it deletes the first node.
here is my code for the ordering of the nodes.
Code:
public void addPlane (PlaneNode planeIn) {
if (start == null) {
start = planeIn;
end = planeIn;
planeIn.setNext(null);
planeIn.setPrevious(null);
end = start;
System.out.println("Thank you the plane has been added");
System.out.println(planeIn.toString());
} else {
// if(end == start ){
// // get the lastNode in queue
// PlaneNode currentFirst = new PlaneNode ();
// currentFirst = this.getEnd();
// currentFirst.setNext(planeIn);
// planeIn.setPrevious(currentFirst);
// planeIn.setNext(null);
// end = planeIn;
// System.out.println(currentFirst.toString());
// System.out.println(planeIn.toString());
// System.out.println("Thank you the plane has been added1");
// } else {
//
// if already nodes in queue
// get the lastNode in queue
PlaneNode currentLast = this.getEnd();
// current update
currentLast.setNext(planeIn);
// new plane update
planeIn.setPrevious(currentLast);
planeIn.setNext(null);
// update queue's last value to point to new plane
this.end = planeIn;
System.out.println("Thank you the plane has been added2");
}
}
The add planeIn PlaneNode works fine. Any help would be great. Thanks
Matt
-
Re: Queuing Nodes
Could you provide some print out that shows what is happening?
What is the code you posted supposed to do?
How can it be tested? Can you provide a small class with a main method that calls the posted method and shows the problem?