Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Print All Paths In Matrix
//Title of this code #include <iostream> #include <vector> using namespace std; template<int rows, int cols> void printAllPaths(vector<int> v, int t[rows][cols], int i, int j) { v.push_back(t[i][j]); // print at the end if ((i == rows - 1) && (j == cols -1)) { for (auto it = v.begin(); it != v.end(); ++it) cout << *it << " "; cout << endl; return; } // copy the vector and recursion if (i < rows - 1) printAllPaths<rows, cols>(v, t, i + 1, j); if (j < cols - 1) printAllPaths<rows, cols>(v, t, i, j + 1); } int main() { int t[3][4] = { {1, 2, 3, 4 }, {5, 6, 7, 8 }, {1, 2, 3, 4 } }; vector<int> v; printAllPaths<3, 4>(v, t, 0, 0); }
run
|
edit
|
history
|
help
0
Ploshtina na pravoagolnik
AWE
cppPyBatScoreSOLID
next greater palindrome
wealth of banks
MCM
pointer array of functions
copy_30-Seconds-of-C++
1st
lock