/*** Saeteurn, San ect_sfs@ecst.csuchico.edu 15b Program 7: Train Schedule ***/ #include using namespace std; #include "stree.h" int main() { STree tree; string command; while(cin >> command) { if(command == "insert") { string cName, desName; cin >> cName >> desName; if(tree.insert(cName,desName)==false) { cerr << "Error: could not insert <" << cName << "," << desName << ">" << endl; } } else if(command == "remove") { string rName; cin >> rName; if(tree.remove(rName) == false) { cerr << "Error: could not remove <" << rName << ">" << endl; } } else if(command == "print") { string city,desOne,desTwo;; cin >> city; if(tree.print(city,desOne,desTwo) == false) { cerr << "Error: <" << city << "> not in tree" << endl; } else { cout << city << ": " << desOne << ", " << desTwo << endl; } } else if(command == "distance") { string oCity,desCity; int dis = 0; cin >> oCity >> desCity; if(tree.distance(oCity,desCity,dis) == false) { cerr << "Error: no path between <" << oCity << "> and <" << desCity << ">" << endl; } else { if(dis > 1 || dis == 0) { cout << oCity << " to " << desCity << " is " << dis << " trains" << endl; } else if(dis == 1) { cout << oCity << " to " << desCity << " is " << dis << " train" << endl; } } } else { cerr << "Error: <" << command << "> is not a valid command" << endl; while(true) { if(cin.peek() == '\n') { break; } cin.ignore(); } } } }