/*search_tree class interface Make a search_tree If passed a value, (start of game tree) make a node with that value Also, be able to append nodes to another node: -Search for the node, if not found return NULL -If found, add a new successor node containing value */ #include "d_node.h" template class search_tree { public: search_tree(); //constructor //Post: An empty game tree has been created. search_tree(Entry x); bool empty() const; //Post: A result of true is returned if the binary tree is empty. //Otherwise, false is returned. d_node *depth_search(Entry value); //start depth_search at root, pass templated function to do what you want private: d_node *recursive_depth_search(deque > *&search_queue, Entry value); d_node *root; }; template search_tree::search_tree() { root=new d_node; root=NULL; if (debug > 0) cout << "\nEmpty tree created."; } template search_tree::search_tree(Entry x) { root = new d_node; root->data = x; if (debug > 0) cout << "\nEmpty tree created."; } /*Use a queue to implement depth first search of our tree. - Push the root node on, then call recursive depth_search */ template d_node *search_tree::depth_search(Entry value) { deque > *search_queue; search_queue = new deque >; search_queue->push_front(*root); return recursive_depth_search(search_queue, value); } /*Takes a deque of nodes, returns a node if value is found, otherwise, NULL 1. Make temp node called state 2. */ template d_node *search_tree::recursive_depth_search(deque > *&search_queue, Entry value) { d_node *state = new d_node; while(!search_queue->empty()) { state = search_queue->front(); if (state->data == value) return state; //If thats what we want, return that node else search_queue->pop_front(); //Else dump it, then //add its successors to queue deque >::iterator iter = state->leaves.begin(); while ((iter != state->leaves.end()) && (search_queue->push_front(iter))) iter++; //I think this will run both conditions. so it will work on the last node. //then rerun search recursive_depth_search(search_queue, value); } return null; }