The function that I am having a problem with is in the middle of this seperated from the rest of the code.

``````#ifndef GRAPH_H

#define GRAPH_H

#include <string>
#include "queue.h"
using namespace std;

class FileOpenError                                 // Exception class -- cannot open input file
{
};

struct EdgeNode										// Structure representing an edge
{
int			destination;						// Index of destination vertex
int			weight;								// Edge weight
EdgeNode*		nextPtr;							// Next edge pointer
};

struct VertexNode									// Structure representing a vertex
{
string		vname;								// Name of vertex
bool			mark;								// Marked flag
EdgeNode*		edgePtr;							// Pointer to list of edges
};

{
private:		//***** Private class members below *****//
VertexNode*	vertices;							// Array of vertex nodes
int			numV;								// Number of vertices

public:		//***** Public members below *****//
Graph(int num);									// Constructor - creates graph with num vertices
~Graph();											// Destructor - deallocates all edge nodes and the vertex list
void DeleteAllEdges();							// Deallocates all edge nodes from all vertices
bool IsEmpty();									// Returns true if graph empty, false otherwise
bool IsFull();									// Returns true if graph full, false otherwise
void AddEdge(string s, string d, int w);	        // Adds edge from source S  to destination D with specified weight W
int IndexIs(string v);							// Returns index of edge from S to D; -1 if not present
int WeightIs(string s, string d);					// Returns weight of vertex V -- assumes V is in graph
void GetToVertices(string s, Queue& q);			// Returns a queue Q of vertices adjacent to vertex V
void ClearMarks();								// Clears vertex marks
void MarkVertex(string v);						// Marks vertex V
bool IsMarked(string v);							// Returns true if vertex V is marked, false otherwise
void Print();										// Write graph to stdout
Queue* DepthFirstSearch(string startVertex, string endVertex);  // Returns ptr to queue containing path or NULL if none
};

void Load(string filename, Graph*& g, string& startVertex, string& endVertex);
// Load graph from named file and values of start and end vertices
// Note: this file attempts to open the named file for input and input all information.
// If the file fails to open, Load throws the FileOpenError exception

#endif

using namespace std;

Graph::Graph(int num):vertices(NULL),numV(num)
{
if (num) {
vertices = new VertexNode[num];
}
}

Graph::~Graph()
{
delete [] vertices;
}

void Graph::DeleteAllEdges()
{
VertexNode* temp = NULL;
}

bool Graph::IsEmpty()
{
return(numV == 0);
}

bool Graph::IsFull()
{

}

{
for(int numNodes = 0; numNodes <= numV; numNodes++)
{
if (vertices[numNodes].vname.empty()) {
vertices[numNodes].vname = v;
vertices[numNodes].edgePtr = NULL;
vertices[numNodes].mark = false;
break;
}
}
}

void Graph::AddEdge(string s, string d, int w)
{
int sV = IndexIs(s);
int dV = IndexIs(d);

EdgeNode *edge = vertices[sV].edgePtr;
vertices[sV].edgePtr = new EdgeNode;
vertices[sV].edgePtr->nextPtr = edge;
vertices[sV].edgePtr->weight = w;
vertices[sV].edgePtr->destination = dV;

}

int Graph::IndexIs(string v)
{
for(int numNodes = 0; numNodes <= numV; numNodes++)
{
if (vertices[numNodes].vname == v) {
return numNodes;
}
}
return -1;
}

int Graph::WeightIs(string s, string d)
{
int sV = IndexIs(s);
int dV = IndexIs(d);

EdgeNode *edge = vertices[sV].edgePtr;
while (edge) {
if (edge->destination == dV) {
return edge->weight;
}
edge = edge->nextPtr;
}
return -1;
}

void Graph::GetToVertices(string s, Queue& q)
{
int sV = IndexIs(s);

EdgeNode *edge = vertices[sV].edgePtr;
while (edge) {
q.Enqueue(s);
edge = edge->nextPtr;
}
}

void Graph::ClearMarks()
{
}``````

The problem function
How do I mark the node as visited?

``````void Graph::MarkVertex(string v)
{
bool marked = v;
}``````
``````bool Graph::IsMarked(string v)
{
}

void Graph::Print()
{

for (int node = 0; node <+ numV; node++){
cout << vertices[node].vname;
if (!vertices[node].edgePtr){
cout << endl;
continue;

}
EdgeNode *edge = vertices[node].edgePtr;
while (edge) {
cout << vertices[edge->destination].vname << edge->weight;
edge = edge->nextPtr;
}
cout << endl;
}

}``````
``````void Graph::MarkVertex(string v)
{
if(v == vname)
marked = true;
}``````
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.