Code:
// there are 2 cases, as node could be at the end, or the one before the end
else if (traverseInOrder.successor == null) {
// this condition is here because if traverse.successor is null, traversal is not incremented
if (iterator.key.compareTo(traverseInOrder.key) < 0) {
traverseInOrder.predecessor.successor = iterator;
iterator.predecessor = traverseInOrder.predecessor;
iterator.successor = traverseInOrder;
traverseInOrder.predecessor = iterator;
}
// this covers the case when successor is null, but the key to insert is greater
else {
iterator.predecessor = traverseInOrder;
traverseInOrder.successor = iterator;
//iterator.successor = null // **even if I put this here, nothing happens**
}
}
The nodes are constructed with all pointer nodes initialized as null, so I don't think that's what was wrong. I did change them to point to null in the code and it made no difference. Still an infinite loop. Or am I misunderstanding what you're saying?