Flatten a multi |
Node * flattenList2 ( Node * head ) { Node * headcop = head ; stack < Node * > save ; save . push ( head ) ; Node * prev = NULL ; while ( ! save . empty ( ) ) { Node * temp = save . top ( ) ; save . pop ( ) ; if ( temp -> next ) save . push ( temp -> next ) ; if ( temp -> down ) save . push ( temp -> down ) ; if ( prev != NULL ) prev -> next = temp ; prev = temp ; } return headcop ; }