Question: need help with above function c++ function: long trapped vals (const vector & v, int rows, int cols) We are looking to see if any
need help with above function c++
function: long trapped vals (const vector& v, int rows, int cols) We are looking to see if any of values in the 2D matrix have 4 neighbors (up, down, left, right) that are all greater than that value. If so, the value is trapped. We return the number of trapped values. For this, we assume that the 2D matrix displays "wrap-around" behavior. Easier to show than explain. 1 2 1 2 3 4 15 0 411 12 1314 1 21 22 23 24 25 2 31 32 33 34 35 3 41 42 43 4445 0 11 12 13 14 121 22 23 24 25 231 32 33 34 35 3 41 42 43 44 45 15 The value at (0,0), index 0, is 11. We are checking the 4 neighbors (up, down, left, right) of that value to see if they are all greater than 11. The value to the right is (0,1), index 1, is 12 The value below at (1,0), index 5, is 21. The value to the left, well there is no value to the left. But we assume the rows wrap around. Thus the a column left of (0,0), index 0 is (0,4), index 4, value 15. The value above, well there is no value above. But we assume the columns also wrap around. Thus a row up from (0,0), index 0, is (3,0) index 15, value 41 11 at (0,0), index 0 is a trapped value. It is the only trapped value in this example