Question text in black, answers in blue.
Queue
interface. It said I didn't have a
peek
method.
It is right, and the reason that your Maze class doesn't have a
peek
method is that it is not trying to be a
Queue,
just to use a Queue. To use the language I'm trying to
emphasize,
a Maze has-a Queue but it isn't-a Queue. You will
want to define a Queue object as a field of the Maze class,
so that every Maze object will have a Queue.
Queue
object with the constructor
Queue<QCell>( )
.
That is because in real Java, Here you can choose any class that implements the interface --
you can find the list of them in the Java API. If we were to go
into your code and replace the Queue
is
an interface, not a class, so there are no Queue
objects, only objects from classes that implement the
Queue
interface. You will need to create an object of
one of those classes and put it in a variable of type
Queue<QCell>
, as in:
Queue<QCell> q = new ArrayDeque<QCell>(
);
ArrayDeque
with a
LinkedList
, for example, it should work just the same.
You don't, at least not yet. Your job when you process a node is to put its neighbors onto the queue. Eventually those neighbors will work their way to the front of the queue, come off, and be processed. At that time, their neighbors will go onto the queue.
Last modified 15 October 2011