diff --git a/DIRECTORY.md b/DIRECTORY.md index b34e8afe6..f19f1c8ac 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -122,6 +122,7 @@ * [Prim](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/graph/prim.cpp) * [Topological Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/graph/topological_sort.cpp) * [Topological Sort By Kahns Algo](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/graph/topological_sort_by_kahns_algo.cpp) + * [Travelling Salesman Problem](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/graph/travelling_salesman_problem.cpp) ## Graphics * [Spirograph](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/graphics/spirograph.cpp) diff --git a/graph/travelling_salesman_problem.cpp b/graph/travelling_salesman_problem.cpp index bc829672c..75003c848 100644 --- a/graph/travelling_salesman_problem.cpp +++ b/graph/travelling_salesman_problem.cpp @@ -1,7 +1,7 @@ /** * @file * @brief [Travelling Salesman Problem] - * (https://en.wikipedia.org/wiki/Travelling_salesman_problem) + * (https://en.wikipedia.org/wiki/Travelling_salesman_problem) implementation * * @author [Mayank Mamgain](http://github.com/Mayank17M) * @@ -17,8 +17,7 @@ * This is the naive implementation of the problem. */ -#include /// header for limits of integral types - +#include /// for limits of integral types #include /// for std::min #include /// for assert #include /// for IO operations @@ -39,7 +38,6 @@ namespace graph { * @param V number of vertices in the graph * */ - int TravellingSalesmanProblem(std::vector> *cities, int src, int V) { //// vtx stores the vertexs of the graph @@ -84,20 +82,20 @@ static void tests() { {0, 20, 42, 35}, {20, 0, 30, 34}, {42, 30, 0, 12}, {35, 34, 12, 0}}; int V = cities.size(); assert(graph::TravellingSalesmanProblem(&cities, 0, V) == 97); - std::cout << "Test 1 Passed..." << std::endl; + std::cout << "1st test passed..." << std::endl; std::cout << "Initiating Test 2..." << std::endl; cities = {{0, 5, 10, 15}, {5, 0, 20, 30}, {10, 20, 0, 35}, {15, 30, 35, 0}}; V = cities.size(); assert(graph::TravellingSalesmanProblem(&cities, 0, V) == 75); - std::cout << "Test 2 Passed..." << std::endl; + std::cout << "2nd test passed..." << std::endl; std::cout << "Initiating Test 3..." << std::endl; cities = { {0, 10, 15, 20}, {10, 0, 35, 25}, {15, 35, 0, 30}, {20, 25, 30, 0}}; V = cities.size(); assert(graph::TravellingSalesmanProblem(&cities, 0, V) == 80); - std::cout << "Test 3 Passed..." << std::endl; + std::cout << "3rd test passed..." << std::endl; } /** @@ -105,7 +103,7 @@ static void tests() { * @returns 0 on exit */ int main() { - tests(); + tests(); // run self-test implementations std::vector> cities = { {0, 5, 10, 15}, {5, 0, 20, 30}, {10, 20, 0, 35}, {15, 30, 35, 0}}; int V = cities.size();