Hi
I keep getting this error when compiling. What can be the problem?
Wrote this same while statement in C++ and it works there.
error: incompatible types
while(nodePtr.next)
^
required: boolean
found: Queue<T>.Node<T>
where T is a type-variable:
T extends Object declared in class Queue
I keep getting this error when compiling. What can be the problem?
Wrote this same while statement in C++ and it works there.
error: incompatible types
while(nodePtr.next)
^
required: boolean
found: Queue<T>.Node<T>
where T is a type-variable:
T extends Object declared in class Queue
public class Queue<T>
{
class Node<T>
{
public T element = null;
public Node<T> next = null;
}
public Node<T> head;
public void enqueue( T element)
{
Node<T> nodePtr = new Node<T>();
if(isEmpty())
{
head = new Node<T>();
head.element = element;
}
else
{
nodePtr = head;
while(nodePtr.next) //ERROR
{
nodePtr = nodePtr.next;
}
nodePtr.next = new Node<T>();
}
}
}