// Karlo V. Miranda // MATH 273 Extra Credit Program #include int main() { int NumberOfVertices; // Number of vertices on graph int Edge [10] [10]; // Adjacency matrix of graph // // Edge[i][j] = 1 if there is an edge joining vertex i to vertex j. // Edge[i][j] = 0 if not // // int i, j, k; // Represent vertices and also counters int NumberOfEdges; // Number of edges in graph fstream EdgeFile; // Internal variable for data file char FileName[30]; // User's name of file int Start, Finish; // Starting and Ending vertices for path int Current, Next; // Vertices in the path finding algorithm int PathLenght; // Length of path int Path[10]; // Holds the path int Visited[10]; // Keeps track of which vertices are // connected to Start vertext in path // algorithm. // Read in graph structure: 1st: get file name and open it. cout << "Enter name of file with graph structure information. "; cin >> FileName; EdgeFile.open( FileName, ios::in); // Next get number of vertices and edges. EdgeFile >> NumberOfVertices >> NumberOfEdges; // Initialize adjacency matrix with no edges. for (i=1; i <= NumberOfVertices; i++) for (j=1; <= NumberOfVertices; j++) Edge[i][j] = 0; // Read in the edges. for (k=1; k <= NumberOfEdges; k++) { EdgeFile >> i >> j; Edge[i][j] = 1; Edge[j][i] = 1; } // Promt & read in starting and ending vertices for path cout << "/n" << "Enter starting and ending vertices "; cin >> Start >> Finish; // Start with no vertices connected to starting vertex. for (i=1; 1 <= NumberOfVertices; i++) Visited[i] = 0; // Initialize path with only starting vertex and mark starting // vertex connected to starting vertex. PathLength = 0; Path[0] = Start; Visited[Start] = 1;