Project4 - Scratch/Graph.hpp #pragma once #include #include #include using namespace std; class Graph{ private: vector > adjacency_list; // mandatory public: Graph() {} //default constructor...

https://docs.google.com/document/d/1g6wruNL1ASqPbgZm04bbUugK6UTqHG-_MxVANVCUctk/edit#


Project4 - Scratch/Graph.hpp #pragma once #include #include #include using namespace std; class Graph{ private: vector<>> adjacency_list; // mandatory public: Graph() {} //default constructor Graph(int); // one argument constructor void addEdge(int, int);//add a new edge from vertex v1 to v2 //edge also needs to be added from v2 to v1 vector BFS(); // Implement Breadth First Search algorithm, using an STL queue // Using an STL queue is mandatory vector BFS_Shortest_Distance(int); // Find Shortest Distance from src vertex // Using an STL queue is mandatory void print_graph(); //optional, for debugging }; Graph::Graph(int){ } void Graph::addEdge(int, int){ } vector Graph::BFS(){ } vector Graph::BFS_Shortest_Distance(int) { } void Graph::print_graph(){ } Project4 - Scratch/main.cpp #include #include #include #include "Graph.hpp" using namespace std; // Global static variables static int testCount = 0; static const int testTotal = 5; static const string GREEN = "\033[32m"; static const string RED = "\033[31m"; static const string RESET = "\033[0m"; vector v1; vector v2; template bool assertVectorEquals(const string& nameOfTest, const vector& expected, const vector& actual); // Main int main(int argc, char const *argv[]) { //BFS Test 1 { Graph G(9);//9 vertices G.addEdge(0, 1); G.addEdge(0, 3); G.addEdge(0, 8); G.addEdge(1, 7); G.addEdge(2, 3); G.addEdge(2, 5); G.addEdge(2, 7); G.addEdge(3, 4); G.addEdge(4, 8); G.addEdge(5, 6); //G.print_graph(); v1 = { 0, 1, 3, 8, 7, 2, 4, 5, 6 }; v2 = G.BFS(); assertVectorEquals("Breadth First Test", v1, G.BFS()); v1.clear(); v2.clear(); } //BFS Test 2 { Graph G(9);//9 vertices G.addEdge(0, 1); G.addEdge(0, 8); G.addEdge(2, 3); G.addEdge(2, 4); G.addEdge(2, 5); G.addEdge(2, 8); G.addEdge(4, 7); G.addEdge(5, 6); G.addEdge(6, 7); G.addEdge(6, 8); //G.print_graph(); v1 = { 0, 1, 8, 2, 6, 3, 4, 5, 7 }; v2 = G.BFS(); assertVectorEquals("Breadth First Test", v1, G.BFS()); v1.clear(); v2.clear(); } //BFS Test 3 { Graph G(5);//5 vertices G.addEdge(0, 1); G.addEdge(0, 4); G.addEdge(1, 2); G.addEdge(1, 3); G.addEdge(2, 3); G.addEdge(3, 4); //G.print_graph(); v1 = { 0, 1, 4, 2, 3 }; v2 = G.BFS(); assertVectorEquals("Breadth First Test", v1, G.BFS()); v1.clear(); v2.clear(); } //BFS Shortest Distance Test 1 { Graph G(8);//8 vertices G.addEdge(0, 1); G.addEdge(0, 3); G.addEdge(1, 2); G.addEdge(3, 4); G.addEdge(3, 7); G.addEdge(4, 5); G.addEdge(4, 6); G.addEdge(4, 7); G.addEdge(5, 6); G.addEdge(6, 7); //G.print_graph(); v1 = { 0, 1, 2, 1, 2, 3, 3, 2 }; v2 = G.BFS_Shortest_Distance(0); assertVectorEquals("Shortest Distance Test", v1, G.BFS_Shortest_Distance(0)); v1.clear(); v2.clear(); } //BFS Shortest Distance Test 2 { Graph G(8);//8 vertices G.addEdge(0, 1); G.addEdge(0, 3); G.addEdge(1, 2); G.addEdge(3, 4); G.addEdge(3, 7); G.addEdge(4, 5); G.addEdge(4, 6); G.addEdge(4, 7); G.addEdge(5, 6); G.addEdge(6, 7); //G.print_graph(); v1 = { 1, 2, 3, 0, 1, 2, 2, 1 }; v2 = G.BFS_Shortest_Distance(3); assertVectorEquals("Shortest Distance Test", v1, G.BFS_Shortest_Distance(3)); v1.clear(); v2.clear(); } cout < "tests="" passed:="" "="">< testcount="">< "/"="">< testtotal="">< "\t("="">< (100*="" float(testcount)/float(testtotal))="">< "%)"="">< endl;="" cin.get();="" return="" 0;="" }="" helper="" functions="" template=""> bool assertVectorEquals(const string& nameOfTest, const vector& expected, const vector& actual) { if (expected.size() == actual.size()) { for (size_t i = 0; i < expected.size();="" i++)="" {="" if="" (expected[i]="" !="actual[i])" {="" red="" colored="" text="" cout="">< red="">< "failed="" "="">< reset="">< nameoftest="">< ":="" expected="" '"="">< expected[i]="">< "'="" but="" actually="" '"="">< actual[i]="">< "'"="">< endl;="" return="" false;="" }="" }="" green="" colored="" text="" cout="">< green="">< "passed="" "="">< reset="">< nameoftest="">< ":="" expected="" and="" actual="" lists="" match:="" {";="" for="" (int="" i="0;" i="">< expected.size();="" i++)="" {="" cout="">< "="" "="">< expected[i];="" }="" cout="">< "="" }"="">< endl;="" testcount++;="" return="" true;="" }="" red="" colored="" text="" cout="">< red="">< "failed="" "="">< reset="">< nameoftest="">< ":="" expected="" size="" '"="">< expected.size()="">< "'="" but="" actually="" size="" is="" '"="">< actual.size()="">< "'"="">< endl;="" return="" false;="">
May 09, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here