diff --git a/code/graph_algorithms/src/hamiltonian_cycle/hamiltonian_cycles.cpp b/code/graph_algorithms/src/hamiltonian_cycle/hamiltonian_cycles.cpp new file mode 100644 index 0000000000..7599c38280 --- /dev/null +++ b/code/graph_algorithms/src/hamiltonian_cycle/hamiltonian_cycles.cpp @@ -0,0 +1,130 @@ +#include +#include +#include +#include +#include + +using namespace std; + +/** + prints all the hamiltonian paths and cycles of the graph +**/ +void printPathsAndCycles(vector > mN,vector > m1, int n) +{ + cout <<"\nThe hamiltonian paths of the graph are : "; + vector paths; + vector edges; + for (int i=0; i lines; + ifstream in ("hamilton.txt"); // opens text file that contains the graph + int n=0; + if (in.is_open()) + { + while ( in >> c ) + { + lines.push_back(c); // stores graph to memory + } + in.close(); + } + n = sqrt(lines.size()); // number of nodes of the graph + vector > m(n); + for (int i=0; i > m1(n); + for (int i=0; i > temp = m1; // save the starting state of M1 cause it is changed later(M1 becomes the MN-1 matrix) + vector > mN(n); + for (int i=0; i