By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,745 Members | 1,873 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,745 IT Pros & Developers. It's quick & easy.

Find indexes in 2d array with if parameters

P: 1
I am trying to find indexes in a 2D array where the number x is either larger than the numbers left and right, and smaller than the numbers above and below, or vice versa.
Mar 3 '17 #1

✓ answered by dev7060

A general algorithm may be:

1: Input the 2D array.

2: Start a loop to initialise the values of array from [0][0] to [0][1]...

3:
Another loop to extract array values
{
-Checking if the value of current element a[i][j] is the largest in current horizontal row (keeping 'i' same)

If so
{ Copy the value of 'j' to another variable.

Now keeping the 'j' same, check whether the current element has the lowest value in its column or not( [0][5], [1][5],...).
If yes, copy the value of 'i' to another variable.}

Now print the value of array element using array[new_var_1][new_var_2] and the new variable's values will be the indices values.
}

Share this Question
Share on Google+
1 Reply


dev7060
100+
P: 100
A general algorithm may be:

1: Input the 2D array.

2: Start a loop to initialise the values of array from [0][0] to [0][1]...

3:
Another loop to extract array values
{
-Checking if the value of current element a[i][j] is the largest in current horizontal row (keeping 'i' same)

If so
{ Copy the value of 'j' to another variable.

Now keeping the 'j' same, check whether the current element has the lowest value in its column or not( [0][5], [1][5],...).
If yes, copy the value of 'i' to another variable.}

Now print the value of array element using array[new_var_1][new_var_2] and the new variable's values will be the indices values.
}
Mar 5 '17 #2

Post your reply

Sign in to post your reply or Sign up for a free account.