Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

need help with above function c++ function: long trapped vals (const vector & v, int rows, int cols) We are looking to see if any

image text in transcribedneed 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Application Development And Design

Authors: Michael V. Mannino

1st Edition

0072463678, 978-0072463675

More Books

Students also viewed these Databases questions

Question

gpt 2 5 9 . .

Answered: 1 week ago