private Node back isn’t used yet, and enqueue (which was push) and dequeue (which was pop) haven’t really been modified except for renaming some things. Again, this was originally a stack but I’m trying to modify it into a queue. I’ve done non-linked list queues and stacks before with ints, but with objects and linked lists I’m sort of lost.
public class DogQueue
{
private Node front = null;
private Node back = null;
private Node element = null;
private int counter = 0;
The above is just setting up variables.
private class Node //This sets up the Linked List
//Data Structure with nodes.
{
private Dog doggy;
private Node nextNode;
private Node firstNode;
Node(Dog newDog)
{
doggy = newDog;
}
}
Node stuff which I don’t quite understand is above.
public void enqueue(Dog aDog) //This should enqueue
//an object of type Dog.
{
Node dogNode = new Node(aDog);
dogNode.nextNode = front;
counter++;
front = dogNode;
}
The above here is unmodified from the push method, just renamed.
public Dog dequeue() //This should output
//the first entry in the list.
{
Dog firstDog = front.doggy;
element = front.firstNode;
counter--;
return firstDog;
}
The above here is where I’m having the most trouble- currently it behaves like pop (getting and removing the last entered element in the list).
public boolean isFull() //Checks to see if List is Full.
{
return ( counter == 5 );
}
I set up the counter to just go up to 5 so I can debug isFull.
public boolean isEmpty() //Checks to see if List is empty
{
if ( counter == 0 )
{
return true;
} else {
return false;
}
}
This just says if counter is zero, then isEmpty is true (otherwise false).
}
I suck at data structures but I believe your enqueue and dequeue are still behaving like pop and push.
The front should point to the head of the queue and the tail one past the last valid object. So the tail should eventually point to null..
I think it should be something like this: