#include #include #include #include #include #include using namespace std; class Node{ char value; vector children; public: Node(char c){ value = c; } void addChild(Node n){ children.push_back(n); return; } void addChild(char n){ Node foo(n); children.push_back(foo); } char getValue(){ return value; } vector getChildren(){ return children; } bool isLeaf(){ return children.size()==0; } bool operator==(Node b){ return b.value==value; } }; void construct(Node *r) { string foo; cout<<"Enter children for "<< r->getValue() <<" (-1 for leaf)"<>foo; if(foo == "-1") return; else{ for(int i = 0; i < foo.length(); i++) { Node t(foo[i]); construct(&t); r->addChild(t); } } } string breadthFirstSearch(Node root, Node goal) { std::queue Q; std::vector children; string path = ""; Q.push(root); while(!Q.empty()) { Node t = Q.front(); path += t.getValue(); Q.pop(); if(t == goal){ return path; } children = t.getChildren(); for (int i = 0; i < children.size(); ++i) { Q.push(children[i]); } } return path; } string depthFirstSearch(Node root, Node goal) { std::stack Q; std::vector children; string path = ""; Q.push(root); while(!Q.empty()) { Node t = Q.top(); path += t.getValue(); Q.pop(); if(t == goal){ return path; } children = t.getChildren(); std::reverse(children.begin(),children.end()); for (int i = 0; i < children.size(); ++i){ Q.push(children[i]); } } return path; } int main(int argc, char** args) { char r; cout<<"Enter root node"<>r; Node root(r); construct(&root); cout<<"Enter Node to search for: "; cin>>r; cout<