History of Idiom 43 > diff from v21 to v22
Edit summary for version 22 by :
↷
Version 21
2015-09-04, 17:56:17
Version 22
2015-10-29, 14:05:14
Idiom #43 Break outer loop
Look for a negative value v in 2D integer matrix m. Print it and stop searching.
Idiom #43 Break outer loop
Look for a negative value v in 2D integer matrix m. Print it and stop searching.
Code
auto indices = findNegativeValue (m, 10, 20);
std::cout << m[indices.first][indices.second] << '\n';
std::pair<int, int> findNegativeValue (int **m, int rows, int columns) {
for (int i = 0; i < rows; ++i) {
for (int j = 0; j < columns; ++j) {
if (m[i][j] < 0) return make_pair (i, j);
}
}
throw "No negative value!";
}
Code
auto indices = findNegativeValue (m, 10, 20);
std::cout << m[indices.first][indices.second] << '\n';
std::pair<int, int> findNegativeValue (int **m, int rows, int columns) {
for (int i = 0; i < rows; ++i) {
for (int j = 0; j < columns; ++j) {
if (m[i][j] < 0) return make_pair (i, j);
}
}
throw "No negative value!";
}
Comments bubble
Comments bubble