Site Loader
Rock Street, San Francisco

/ class templates#include using namespace std;
templateGraphType::GraphType(int maxV){ numVertices = 0; maxVertices = maxV; vertices = new VertexTypemaxV; edges = new intmaxV; for(int i = 0; i < maxV; i++) edgesi = new intmaxV; marks = new boolmaxV;} templateGraphType::~GraphType(){ delete vertices; for(int i = 0; i < maxVertices; i++) delete edgesi; delete edges; delete marks;} template void DepthFirstSearch(GraphType graph, VertexType startVertex, VertexType endVertex){
StackType stack; QueType vertexQ;  bool found = false; VertexType vertex; VertexType item;  graph.ClearMarks(); stack.Push(startVertex); do { stack.Pop(vertex); if(vertex == endVertex) found = true; else { if(!graph.IsMarked(vertex)) { graph.MarkVertex(vertex); graph.GetToVertices(vertex, vertexQ); while(!vertexQ.IsEmpty()) { vertexQ.Dequeue(item); if(!graph.IsMarked(item)) stack.Push(item); } } } while(!stack.IsEmpty() && !found);  if(!found) cout << "Path not found" << endl; } }template
void GraphType::GetToVertices(VertexType vertex,QueTye& adjvertexQ){ int fromIndex; int toIndex;  fromIndex = IndexIs(vertices, vertex); for(toIndex = 0; toIndex < numVertices; toIndex++) if(edgesfromIndextoIndex != NULL_EDGE) adjvertexQ.Enqueue(verticestoIndex);} templatevoid BreadthFirtsSearch(GraphType graph, VertexType startVertex, VertexType endVertex);{ QueType queue; QueType vertexQ;//   bool found = false; VertexType vertex; VertexType item;  graph.ClearMarks(); queue.Enqueue(startVertex); do { queue.Dequeue(vertex); if(vertex == endVertex) found = true; else { if(!graph.IsMarked(vertex)) { graph.MarkVertex(vertex); graph.GetToVertices(vertex, vertexQ);  while(!vertxQ.IsEmpty()) { vertexQ.Dequeue(item); if(!graph.IsMarked(item)) queue.Enqueue(item); } } } } while (!queue.IsEmpty() && !found);  if(!found) cout << "Path not found" << endl;}

Post Author: admin

x

Hi!
I'm Eunice!

Would you like to get a custom essay? How about receiving a customized one?

Check it out