Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
printAllPathsInMatrix
//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]); if ((i == rows - 1) && (j == cols -1)) { for (auto it = v.begin(); it != v.end(); ++it) cout << *it << " "; cout << endl; return; } 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
Dar
Interview Prep
shuffle_example
Splitwise Problem - 2
std::string(pid_t)
wealth of banks
cppPySuper
Odwrócone podciągi
List Add v3
fibonacci