#include #include #include #include #include #include #include #include using namespace std; class node { private: string name; list data; public: string getName() {return this->name;} void setName(const string &newName) {name=newName;} list getData() {return this->data;} void setData(const list &newData) {data=newData;} node() {} virtual ~node() {} //functie de afisare a unui nod in formatul Newick friend ostream& operator << (ostream &out,const node &n) { if(n.data.size()!=0) { out<<"("; for(list::const_iterator i=n.data.begin() ; i!=n.data.end() ; i++) if (i == n.data.begin()) out << *i; else out << "," << *i; out << ")"; } out << n.name; return out; } }; //functia face conversia de la formatul Newick la obiectul node node build_tree(const string &line) { string cur_word; stack st; node temp; list cur_data; for(int i = 0 ; i t; t = temp.getData(); t.clear(); temp.setData(t); temp.setName(""); } else if(line[i] == ')') { node temp_arr; temp_arr.setName(cur_word); temp_arr.setData(cur_data); cur_data.clear(); cur_word = ""; list t; t = temp.getData(); t.push_back(temp_arr); temp.setData(t); cur_data = temp.getData(); temp = st.top(); st.pop(); } else if(line[i] == ',') { node temp_arr; temp_arr.setName(cur_word); temp_arr.setData(cur_data); cur_data.clear(); cur_word = ""; list t; t = temp.getData(); t.push_back(temp_arr); temp.setData(t); } else cur_word.append(line.substr(i, 1)); }//end of for node temp_arr; temp_arr.setName(cur_word); temp_arr.setData(cur_data); temp = temp_arr; return temp; } node tree_merge(const node& first, const node& second) { return first; }//end of tree merge int main(int argc, char* argv[]) { string line1="(b,c)a"; string line2="((e)b,d)a"; node node1=build_tree(line1); node node2=build_tree(line2); //rezultatul trebuie sa fie ((e)b,c,d)a in ambele cazuri cout<