Skip to content

Commit

Permalink
Updated function to printAll towns and roads - still needs some work
Browse files Browse the repository at this point in the history
  • Loading branch information
elijahbigk77 committed Apr 18, 2022
1 parent ce456b7 commit 7cec83d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
2 changes: 1 addition & 1 deletion project5.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ using namespace std;
int main() {
while(!cin.eof()) {
Province theProvince(cin);
theProvince.printAll(cout);
theProvince.printAll(0, cout);
}
}

38 changes: 23 additions & 15 deletions province.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,26 @@ Province::Province(std::istream & source) {
}
}

// void Province::printAll(std::ostream & output) {
// output << "The input data is:" << endl << endl;
// cout << endl << "Size of towns: " << sizeof(&_towns)/sizeof(&_towns[0]) << endl;
// for (int i = 0; i < sizeof(&_towns)/sizeof(&_towns[0]); i++) {
// output << _towns[i]._name << endl;
// for (Road _road: _towns[i]._roads) {
// output << "\t" << road._tail << " " << road._length << " mi";
// if (road._isBridge == 'B' || 'b') {
// output << " via bridge" << endl;
// } else {
// output << endl;
// }
// }
// }
// }
void Province::printAll(int start, std::ostream & output) {
// keep track of whether a town(vertex) has been scheduled to be visited
bool scheduled[_numberOfTowns];
for (int i = 0; i < _numberOfTowns; i++){
scheduled[i] = false;
}

// Keep track of which towns have been visited
queue <int> toVisit; // use queue to keep track of which town to visit next
toVisit.push(start);
scheduled[start] = true;
output << "The input data is:" << endl << endl;

// Visit every town in the queue
while (!toVisit.empty()) {
int current = toVisit.front();
toVisit.pop();

output << " ";
output << _towns[current]._name << endl;
}

}
2 changes: 1 addition & 1 deletion province.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Province
* Print towns and roads in province in breadth-first search order
* @param output Stream to print data to
*/
void printAll(std::ostream & output);
void printAll(int start, std::ostream & output);
void printShortestPath(std::ostream & output) const;

/**
Expand Down

0 comments on commit 7cec83d

Please sign in to comment.