question: protected N buildTree ( int [ ] msg , int cur , int parent , ArrayList < N > nodes ) { int c = 0 ; for ( int i = 0 ; i < msg . length ; i += 2 ) { if ( msg [ i ] == cur && msg [ i + 1 ] != parent ) { c ++ ; } if ( msg [ i + 1 ] == cur && msg [ i ] != parent ) { c ++ ; } } List < N > children ; if ( c > 0 ) { children = new ArrayList < > ( c ) ; } else { children = Collections . emptyList ( ) ; } for ( int i = 0 ; i < msg . length ; i += 2 ) { if ( msg [ i ] == cur && msg [ i + 1 ] != parent ) { c -- ; children . add ( buildTree ( msg , msg [ i + 1 ] , cur , nodes ) ) ; } if ( msg [ i + 1 ] == cur && msg [ i ] != parent ) { c -- ; children . add ( buildTree ( msg , msg [ i ] , cur , nodes ) ) ; } } assert ( c == 0 ) ; N node = makeNode ( cur , children ) ; nodes . set ( cur , node ) ; return node ; }
target:  Recursive tree build method.