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