Flatten a multi |
Node flattenList2 ( Node head ) { Node headcop = head ; Stack < Node > save = new Stack < > ( ) ; save . push ( head ) ; Node prev = null ; while ( ! save . isEmpty ( ) ) { Node temp = save . peek ( ) ; 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 ; }