diff --git a/alib2data/src/tree/common/TreeAuxiliary.h b/alib2data/src/tree/common/TreeAuxiliary.h index 81aeeed88218ce000cd022cb158587ecd91f8a90..34d219277c6dc8bc204e131bb00234303d3d83ea 100644 --- a/alib2data/src/tree/common/TreeAuxiliary.h +++ b/alib2data/src/tree/common/TreeAuxiliary.h @@ -84,26 +84,22 @@ ext::tree < common::ranked_symbol < SymbolType, RankType > > TreeAuxiliary::unra template < class SymbolType, class RankType > ext::tree < common::ranked_symbol < SymbolType, RankType > > TreeAuxiliary::postfixToTree ( const ext::vector < common::ranked_symbol < SymbolType, RankType > > & from ) { - std::stack < ext::tree < common::ranked_symbol < SymbolType, RankType > > > tree_stack; - for ( auto x : from ) { + for ( const common::ranked_symbol < SymbolType, RankType > & x : from ) { if ( ( unsigned ) x.getRank ( ) == 0 ) { - tree_stack.push ( ext::tree < common::ranked_symbol < SymbolType, RankType > > ( common::ranked_symbol < SymbolType, RankType > ( x.getSymbol ( ), x.getRank ( ) ), ext::vector < ext::tree < common::ranked_symbol < SymbolType, RankType > > > ( ) ) ); + tree_stack.push ( ext::tree < common::ranked_symbol < SymbolType, RankType > > ( x, ext::vector < ext::tree < common::ranked_symbol < SymbolType, RankType > > > ( ) ) ); } else { - unsigned children_size = ( unsigned ) x.getRank ( ); - ext::list < ext::tree < common::ranked_symbol < SymbolType, RankType > > > childrenList; + ext::vector < ext::tree < common::ranked_symbol < SymbolType, RankType > > > children; - for ( unsigned i = 0; i < children_size; ++i ) { - ext::tree < common::ranked_symbol < SymbolType, RankType > > child = tree_stack.top ( ); + for ( unsigned i = 0; i < ( unsigned ) x.getRank ( ); ++i ) { + children.push_back ( tree_stack.top ( ) ); tree_stack.pop ( ); - childrenList.push_front ( child ); } - ext::vector < ext::tree < common::ranked_symbol < SymbolType, RankType > > > children { - std::begin ( childrenList ), std::end ( childrenList ) - }; - tree_stack.push ( ext::tree < common::ranked_symbol < SymbolType, RankType > > ( common::ranked_symbol < SymbolType, RankType > ( x.getSymbol ( ), x.getRank ( ) ), std::move ( children ) ) ); + std::reverse ( children.begin ( ), children.end ( ) ); + + tree_stack.push ( ext::tree < common::ranked_symbol < SymbolType, RankType > > ( x, std::move ( children ) ) ); } }