Node < E > successor ( ) { Node < E > f = nextNonmarker ( ) ; for ( ; ; ) { if ( f == null ) return null ; if ( ! f . isDeleted ( ) ) { if ( f . getPrev ( ) != this && ! isDeleted ( ) ) f . setPrev ( this ) ; // relink f's prev return f ; } Node < E > s = f . nextNonmarker ( ) ; if ( f == getNext ( ) ) casNext ( f , s ) ; // unlink f f = s ; } }
Returns the next non - deleted node swinging next pointer around any encountered deleted nodes and also patching up successor s prev link to point back to this . Returns null if this node is trailer so has no successor .