How do you find a position of an element in a queue?

Jul 21, 2022 at 11:47pm
I'm not sure I'm using correct terminology.

How would I create a queue for a 2d array that finds the position of a specific element and increases the value of all the elements that touch that position?

For example

Input reads:

[1][1][1][1][1]
[1][1][1][1][1]
[1][0][0][1][1]
[1][1][1][1][1]

I want it to change to:

[2][2][2][2][3]
[1][1][1][1][2]
[1][0][0][1][2]
[1][1][1][1][2]

The farther the element from 0, the higher the elements value becomes. Only increase by 1 at a time.
Jul 21, 2022 at 11:56pm
In C++ queue has a very specific meaning, it is a C++ stdlib container.

https://en.cppreference.com/w/cpp/container/queue

There are only two parts of a std:queue you can access, the front and the back. you can't access any other elements.

A 2D container is also known as a "matrix." There are several matrix manipulation 3rd party libraries available, Eigen is the most popular/common mentioned.

https://eigen.tuxfamily.org/index.php?title=Main_Page

I don't use the library myself.
Jul 22, 2022 at 12:21am
Thank you, I appreciate the suggestion. I'm going to search for more matrix manipulation abilities.
Jul 22, 2022 at 2:37am
this looks similar to the classic game minesweeper and how it provides hints to the user (its backwards, but same idea).
eigen is more for linear algebra than this; you may be just as well off rolling your own solution? I can't think of anything in matrix processing that does this (?) but it may be doable with some form of image manipulation (eg custom filters can sort of do this, if modified slightly, that may give you a starting point algorithm)
Jul 22, 2022 at 5:30am
std::queue<pair<int,int>>

You don’t need to “create” anything - just use the standard library.

Your problem has nothing whatsoever to do with matrix manipulation, other than storing things in an array.

Anyway, I think @mbozzi has answered your question in another thread. (Best not to create multiple threads for the same problem.) Maybe just add diagonal adjacency to that, looking at your example.
https://cplusplus.com/forum/general/284365/#msg1231853
Last edited on Jul 22, 2022 at 7:23am
Jul 22, 2022 at 8:27am
Jul 23, 2022 at 12:18pm
Thank you all! I'm testing several suggestions. I appreciate your help here.
Topic archived. No new replies allowed.