Untitled
unknown
plain_text
2 years ago
671 B
6
Indexable
#include <iostream>
#include <vector>
std::vector<std::vector<int>> matrix = {
{1, 2, 5, 6},
{3, 4, 7, 8},
{9, 10, 13, 14},
{11, 12, 15, 16}
};
void doPrint(std::vector<std::vector<int>> &matrix, int row, int col){
if(row<0|| row>=matrix.size() || col<0 || col>=matrix[0].size()) return;
std::cout<<matrix[row][col]<<" ";
if(!(col&1)) doPrint(matrix, row, col+1);
else if(!(row&1) && col&1) doPrint(matrix, row+1, col-1);
else if(col==matrix[0].size()-1 && row&1) doPrint(matrix, row+1, 0);
else if(row&1 && col&1) doPrint(matrix, row-1, col+1);
}
int main(){
doPrint(matrix, 0, 0);
return 0;
}Editor is loading...