Beispiel #1
0
void AGraph::DFS_makeVisualizers(TArray<int32>& stack,
								 int32 vIndex)
{
	if (mark[vIndex] == nullptr || mark[vIndex]->visited) return;

	markVertex(vIndex);
	stack.Push(vIndex);
	//generate a visulaizer for an unvisited vertex
	auto vertexMesh = makeVertexMeshForVertex(vIndex);
	vertexMeshes.Add(vertexMesh);

	for (auto v = first(vIndex);
		v != nullptr;
		v = next(vIndex, v->vertexIndex))
	{
		bool isBackEdge = v->visited && vIndex < v->vertexIndex;

		if (!v->visited || isBackEdge)
		{
			//generate an edge
			auto edgeMesh = makeEdgeMeshForEdge(vIndex, v->vertexIndex);
			initializeEdgeMesh(edgeMesh, mark[vIndex], v);
			edgeMeshes.Add(edgeMesh);

			if (!v->visited)
			{
				DFS_makeVisualizers(stack, v->vertexIndex);
			}
		}
	}

	stack.Pop();
}
Beispiel #2
0
void Graph::DFS(int u)
{
    markVertex(u);
    cout << u << " ";

    for (int i = 0; i < NODE_COUNT; i++)
	if (isAdjacent(u,i) && !isMarked(i))
	    DFS(i);
}
Beispiel #3
0
//BREAD FIRST SEARCH
void Graph::BFS()
{
    unmarkAll();
    int u = 0;
    queue<int> q;
    markVertex(u);
    q.push(u);

    while (!q.empty()) {
	u = q.front();
	q.pop();
	for (int i = 0; i < NODE_COUNT; i++) 
	    if (isAdjacent(u,i) && !isMarked(i)) {
		q.push(i);
		markVertex(i);
	    }
	cout << u << " ";
    }
}