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