'The type Queue is not generic
I have problem with BreadthFirstPath API. When I would like to declare a Queue object in that API, they send me the error "The type Queue is not generic. It cannot be paramterizied.", despite the fact that I am declaring Queue class generic. Does anyone have solution for my problem?
public class BreadthFirstPaths {
private boolean[] marked;
private int[]edgeTo;
private void bfs(Graph G, int s) {
Queue<Integer> q = new Queue<Integer>();
q.enqueue(s);
marked[s] = true;
while(!q.isEmpty())
{
int v = q.dequeue();
for(int w: G.adj(v)) {
if(!marked[w]) {
q.enqueue(w);
marked[w] = true;
edgeTo[w] = v;
}
}
}
}
}
public class Queue<Item> implements Iterable<Item>{
private Node<Item> first;
private Node<Item> last;
private int n;
private class Node<Item>{
private Node<Item> next;
private Item item;
}
public Queue() {
first = null;
last = null;
n = 0;
}
public boolean isEmpty() {
return first == null;
}
public void enqueue(Item item) {
Node<Item> oldlast = last;
last = new Node<Item>();
last.item = item;
last.next = null;
if(isEmpty()) first = last;
else oldlast.next = last;
n++;
}
public Item dequeue() {
if(isEmpty()) throw new NoSuchElementException("Queue underflow");
Item item = first.item;
first = first.next;
n--;
if(isEmpty()) last = null;
return item;
}
@Override
public Iterator<Item> iterator() {
// TODO Auto-generated method stub
return null;
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
