int insertElement ( int list , int beforeNode , int data ) { int node = newNode_ ( ) ; int prev = - 1 ; if ( beforeNode != nullNode ( ) ) { prev = getPrev ( beforeNode ) ; setPrev_ ( beforeNode , node ) ; } setNext_ ( node , beforeNode ) ; if ( prev != nullNode ( ) ) setNext_ ( prev , node ) ; int head = m_lists . getField ( list , 0 ) ; if ( beforeNode == head ) m_lists . setField ( list , 0 , node ) ; if ( beforeNode == nullNode ( ) ) { int tail = m_lists . getField ( list , 1 ) ; setPrev_ ( node , tail ) ; if ( tail != - 1 ) setNext_ ( tail , node ) ; m_lists . setField ( list , 1 , node ) ; } setData ( node , data ) ; setListSize_ ( list , getListSize ( list ) + 1 ) ; if ( m_b_store_list_index_with_node ) setList_ ( node , list ) ; return node ; }
Inserts a new node before the given one .