Move the code to find the predecessor into one function, as it is shares quite some similarities: In both cases we first need to find the immediate predecessor/successor, then we need to find the immediate predecessor if the iterator is not already pointing at it.