C++ Recursion - adding tree data to list in order -


my code below - i'm trying return main list of aircrafts i'm getting binary tree in order (smallesty largest). code below, root node twice. i've been working on hours... suggestions?

thanks, charlotte

std::list<aircraft> tree::buildlist() {     std::list<aircraft> aircraftlist;     if (_root != 0)     {         aircraftlist = buildlisthelp(_root, aircraftlist);         aircraftlist.push_front(*_root->getaircraftdata());          }     return aircraftlist; }  std::list<aircraft> tree::buildlisthelp(node* node, std::list<aircraft> aircraftlist) {     //aircraftlist.push_back(*node->getaircraftdata())     /*if (node->getleft() != 0)     {*/     if (node==0)         return aircraftlist;     buildlisthelp(node->getleft(), aircraftlist);     //}     aircraftlist.push_back(*node->getaircraftdata());     /*if (node->getright() != 0)     {*/     buildlisthelp(node->getright(), aircraftlist);       //}     return aircraftlist; } 

assuming _root declared

node* _root; 

you pushing twice:

aircraftlist.push_front(*_root->getaircraftdata());     aircraftlist.push_back(*node->getaircraftdata()); 

in first call of buildlisthelp


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -