编译器中显示的完整错误:ListPriorityQueue.java:11: 错误:找不到符号 public class ListPriorityQueue > 实现 PriorityQueue ^ 符号:类 PriorityQueue 我只是不明白,因为显示的错误信息并不十分丰富。PriorityQueue 确实存在于包中。
package data_structures;
import java.util.Iterator;
import java.util.NoSuchElementException;
/**
* This is a linked list implementing ListADT interface
* @param <E> The data type of the linked list
*/
public class ListPriorityQueue <E extends Comparable<E>> implements PriorityQueue<E>
{
int count; //number of elements in the queue
Node<E> first; //Head of the queue
Node<E> last; //Tails of the queue
int capacity= DEFAULT_MAX_CAPACITY;
//Constructor
public ListPriorityQueue()
{
first = null;
last = null;
}
public ListPriorityQueue(int capacity )
{
first = null;
last = null;
this.capacity= capacity;
}
public boolean insert(E object)
{
if(this.isFull())
return false;
Node<E> prev = null;
Node<E> current = this.first;
Node<E> temp = new Node<E>(object);
// while (current != null && current.getData().pValue >= item.pValue)
while (current != null && current.getData().compareTo(temp.getData())<0 )
{
prev = current;
current = current.getNext();
}
if (prev == null)
{
temp.setNext(this.first);
this.first = temp;
}
else
{
temp.setNext(current);
prev.setNext( temp);
}
count++;
return true;
}
public E remove()
{
E result;
//If the list is empty
if(count==0)
{
return null;
}
result= first.getData();
first= first.getNext();
count--;
if(count==0)
{
last=null;
}
return result;
}
public E peek()
{
if(count==0)
{
return null;
}
return first.getData(); //Return first element without removing
}
public int size()
{
return count;
}
public boolean contains (E target)
{
boolean found= false;
//If there is no element in the list
if (count==0)
{
return found;
}
Node<E> current;
current = first;
// iterate the list looking for target
while(!found && current != null)
{
//If current node data same as target
if(target.equals(current.getData()))
{
found = true;
}
else
current = current.getNext();
}
return found;
}
public Iterator<E> iterator()
{
return new TheIterator();
}
public void clear()
{
//Loop to removeFirst till the list is empty
while (!this.isEmpty())
{
this.remove();
}
}
public boolean isEmpty()
{
if(count == 0){
return true;}
else{return false;}
}
public boolean isFull()
{
if(count == capacity){
return true;}
else { return false;}
}
class Node<E>
{
private Node<E> next; //Next element
private E data; //Data
//Initialize Node
public Node (E obj)
{
next = null;
data = obj;
}
//Return next node
public Node<E> getNext()
{
return next;
}
//Set the next node
public void setNext (Node<E> node)
{
next = node;
}
//Get data of the node
public E getData()
{
return data;
}
//Set node data
public void setData (E obj)
{
data = obj;
}
}
/**
*
* Iterartor for the passed in collection
* @param <E>
*/
class TheIterator<E> implements Iterator<E>
{
private Node<E> current;
public TheIterator ()
{
current = (Node<E>)first;
}
public boolean hasNext()
{
return current != null;
}
public E next()
{
if ( hasNext() == false) //If there are no more elements
throw new NoSuchElementException();
E result = current.getData();
current = current.getNext();
return result;
}
public void remove()
{
throw new UnsupportedOperationException(); //remove not supported
}
}
}