-4
这是我在我的Josephus类中添加的方法,我应该使用一个循环链表。我在我的课的几个领域得到空指针异常,但都是因为这种方法。任何人都可以通过查看这段代码看到任何显而易见的错误吗?这个Java代码有什么问题
/** Inserts the specified element in the list at the
last position
@param dataItem the element to add
*/
// Complexity O(1)
@SuppressWarnings({ "unchecked" })
public void add(E dataItem) {
Node <E> node = new Node <E> (dataItem,null,null);
if (count == 0){ // list is empty
head = node.previous= node;
}
else {
head.previous.next = node;
node.previous = head.previous;
head.previous = node;
}
count++;
}
全码:http://pastebin.com/k4Hmbqmw
有得多未知变量。所以它很容易看到问题。 – rekire
你在其他部分使用花括号吗? –
重要的是你在if和else块周围缺少'{}'。 –