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

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.
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.
Thank you, I appreciate the suggestion. I'm going to search for more matrix manipulation abilities.
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)
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
Thank you all! I'm testing several suggestions. I appreciate your help here.
Topic archived. No new replies allowed.