void BFS(NodeMap* nMap, string startNode, string goalNode) { QUEUE *q = new QUEUE(); NodeList* nlist = nMap->find(startNode)->second; for (NodeList::iterator it = nlist->begin(); it != nlist->end(); it++) { (*it)->path->push_back(startNode); (*it)->visitedNodes->insert(pair<string, NodeList*> (startNode, nlist)); q->push(*it); } cout << startNode << endl; while(!q->empty()) { Node* firstNode = q->front(); q->pop(); cout << firstNode->name << endl; if (firstNode->name == goalNode) { cout << "END" << endl; cout << "Final path : "; for(list<string>::iterator sit = firstNode->path->begin(); sit != firstNode->path->end(); sit++) { cout << (*sit) << endl; cout << firstNode->name << endl; } break; } if (firstNode->visitedNodes->find(firstNode->name) != firstNode->visitedNodes->end()) { continue; } nlist = nMap->find(firstNode->name)->second; for (NodeList::iterator it = nlist->begin(); it != nlist->end(); it++) { (*it)->path = new list<string>(firstNode->path->begin(), firstNode->path->end()); (*it)->visitedNodes = new NodeMap(firstNode->visitedNodes->begin(), firstNode->visitedNodes->end()); (*it)->path->push_back(firstNode->name); (*it)->visitedNodes->insert(pair<string, NodeList*> (firstNode->name, NULL)); q->push(*it); } } }
/** Basic tests LfHeterQueue with a non-polymorphic base */ template <typename QUEUE> static void lf_heterogeneous_queue_basic_void_tests() { { QUEUE queue; DENSITY_TEST_ASSERT(queue.empty()); } { QUEUE queue; queue.clear(); queue.push(1); DENSITY_TEST_ASSERT(!queue.empty()); queue.clear(); DENSITY_TEST_ASSERT(queue.empty()); queue.clear(); } }
int main(){ int a = 0; /* init(); for (a = 0; a < MAX_SIZE; a++) push(a+1); for (a = 0; a < MAX_SIZE ; a++) pop(); */ QUEUE q; for (a = 0; a < MAX_SIZE; a++) q.push(a + 1); for (a = 0; a < MAX_SIZE; a++) q.pop(); return 0; }