-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
80 lines (64 loc) · 2.06 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//---------------------------------------------------------------------------
// lab3.cpp
//---------------------------------------------------------------------------
// This code tests the basic functionality of the classes to perform
// Dijkstra's algorihms and depth-first search for CSS 343 Lab 3.
// It is not meant to exhaustively test the class.
//
// Assumptions:
// -- students can follow the directions to interface with this file
// -- text files "data31.txt" and "data32.txt" are formatted as described
// -- Data file data3uwb provides an additional data set for part 1;
// it must be edited, as it starts with a description how to use it
//---------------------------------------------------------------------------
#include <iostream>
#include <fstream>
#include "graphl.h"
#include "graphm.h"
using namespace std;
int main()
{
// part 1
ifstream infile1("/Users/shyawnkarim/Documents/css343/Assignment3/DijkstrasShortestPath/data31.txt");
if (!infile1)
{
cout << "File could not be opened." << endl;
return 1;
}
//for each graph, find the shortest path from every node to all other nodes
for (;;)
{
GraphM G;
G.buildGraph(infile1);
if (infile1.eof())
{
break;
}
G.findShortestPath();
G.displayAll(); // display shortest distance, path to cout
G.display(3, 1); // display path from node 3 to 1 to cout
G.display(1, 2);
G.display(1, 4);
}
// part 2
ifstream infile2("/Users/shyawnkarim/Documents/css343/Assignment3/DijkstrasShortestPath/data32.txt");
if (!infile2)
{
cout << "File could not be opened." << endl;
return 1;
}
//for each graph, find the depth-first search ordering
for (;;)
{
GraphL G;
G.buildGraph(infile2);
if (infile2.eof())
{
break;
}
G.displayGraph();
G.depthFirstSearch(); // find and display depth-first ordering to cout
}
cout << endl;
return 0;
}