Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Matrix spiral print
//Title of this code #include <iostream> using namespace std; template<int rows, int cols> void spirallyPrint(const int t[rows][cols]) { int hStart = 0; // horizontal start int hEnd = cols - 1; // horizontal end int vStart = 0; // vertical start int vEnd = rows - 1; // vertical end while (hStart <= hEnd && vStart <= vEnd) { // horizontal left to right if (vStart <= vEnd) for (int i = hStart; i <= hEnd; ++i) cout << t[vStart][i] << " "; ++vStart; // first row done // vertical top to bottom if (hStart <= hEnd) for (int i = vStart; i <= vEnd; ++i) cout << t[i][hEnd] << " "; --hEnd; // last column done // horizontal right to left if (vStart <= vEnd) for (int i = hEnd; i >= hStart; --i) cout << t[vEnd][i] << " "; --vEnd; // last row done // vertical bottom to top if (hStart <= hEnd) for (int i = vEnd; i >= vStart; --i) cout << t[i][hStart] << " "; ++hStart; // first column done } } int main() { int t[3][4] = { {1, 2, 3, 4}, {3, 4, 5, 6}, {5, 6, 7, 8} }; spirallyPrint<3, 4>(t); }
run
|
edit
|
history
|
help
0
FindMissingNewt
MapGrocery
Decimal to Binary
BinTree palyground
QuickDoubly
Einstein's Physics
Simple use of function templete and namespace
Diferenciacion e integracion beta 0.1
ExtremeValues
cppOverride