1 回答
TA貢獻(xiàn)1886條經(jīng)驗(yàn) 獲得超2個(gè)贊
這是你做錯(cuò)了x.right()。情況也是如此x.left()
if (x.right() == null) {
? ? ? ? //TreapNode y = new TreapNode(key, priority);
? ? ? ? TreapNode z = x.right; // z = null
? ? ? ? x.right = z.left;? // z.left will throw NPE
應(yīng)該
if (x.right() == null) {
? ?x.right() = new TreapNode(key, priority);
? ?return x; // return parent node?
}
另外,我認(rèn)為這也是一個(gè)錯(cuò)誤的比較,int不能null但是Integer類可以
int compare = key.compareTo(x.element());? //comoareTo return an int?
if (x == null){? // does not make sense to compare and int type to Object type
? ....
}
添加回答
舉報(bào)
