int concatenateLists ( int list1 , int list2 ) { int tailNode1 = m_lists . getField ( list1 , 1 ) ; int headNode2 = m_lists . getField ( list2 , 0 ) ; if ( headNode2 != nullNode ( ) ) // do not concatenate empty lists { if ( tailNode1 != nullNode ( ) ) { // connect head of list2 to the tail of list1. m_listNodes . setField ( tailNode1 , 1 , headNode2 ) ; // set the tail of the list1 to be the tail of list2. m_lists . setField ( list1 , 1 , m_lists . getField ( list2 , 1 ) ) ; } else { // list1 is empty, while list2 is not. m_lists . setField ( list1 , 0 , headNode2 ) ; m_lists . setField ( list1 , 1 , m_lists . getField ( list2 , 1 ) ) ; } } if ( m_b_allow_navigation_between_lists ) { int prevList = m_lists . getField ( list2 , 2 ) ; int nextList = m_lists . getField ( list2 , 3 ) ; if ( prevList != nullNode ( ) ) m_lists . setField ( prevList , 3 , nextList ) ; else m_list_of_lists = nextList ; if ( nextList != nullNode ( ) ) m_lists . setField ( nextList , 2 , prevList ) ; } freeList_ ( list2 ) ; return list1 ; }
Returns list1 .