我需要编写自己的 Deque 类,并且必须使用双向链表实现来存储数据。问题是编写方法pushfromLeft(Thing thing),它将插入到双端队列的左侧。以下是我迄今为止所拥有的,但似乎不起作用。
public void pushLeft(Thing thing) {
Node beg = new Node();
Node end = new Node();
Node T = new Node();
if(isEmpty())
{
beg = first;
end = last;
beg = end;
T = beg.thing;
N++;
}
else
{
beg = beg.next;
end = end.next;
T = beg.previous;
N++;
}
最佳答案
除了更改 N
和 item
之外,您在该方法中所做的几乎没有任何影响。想必您应该首先
进行修改。如果您提供类(class)的字段及其含义,以供上下文引用,将会有所帮助。例如,不清楚 item
是什么。
您还应该提出不同的命名成员和局部变量的约定,或者一致使用 this.
,或两者兼而有之。
关于java - 创建 Deque 类方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10196973/