0
我只是好奇,我有一个类实现了一个队列,它目前有一个项目...我很好奇,哪里将是最有效或最干净的位置来初始化其他项目,我希望添加到队列中......这是作业的一部分,所以请提供解释,而不仅仅是回答!在此先感谢...这是我建立了类...在Java中执行队列
import java.util.*;
public class Queue<T> extends Node<T> {
private LinkedList<T> list;
// Queue constructor
public Queue() {
// Create a new LinkedList.
list = new LinkedList<T>();
}
//check if empty
public boolean isEmpty() {
return (list.size() == 0);
}
//add items to queue
public void enqueue(Object item) {
// Append the item to the end of our linked list.
list.add((T) item);
}
//remove items from queue
public T dequeue() {
T item = list.get(1);
list.remove(1);
// Return the item
return item;
}
//check top item
public T peek() {
return list.get(1);
}
//check size of queue
public int size() {
return list.size();
}
}
你对此事的看法? – 2013-03-04 17:27:23
为什么'Object'而不是'T'到处都是? – 2013-03-04 17:27:28
你确定你可以使用'LinkedList'来操纵你的队列吗?它基本上是一个包装,可能你的教授不会接受它。 – 2013-03-04 17:28:09