I need to create linked list for every M row with N elements of that matrix
example, first linked list is 5, 18, 32, 87, second is 11, 76... etc
I would advice taking the following approach:
To do this part, I would advise the following approach.
(1) create a size M array of std::list's. Size M because each row needs to be a separate list, therefore you need M lists. Instead of making M separate lists, simply make an array of M lists.
That declaration would be like this: std::list<int> lst[M];
(2) Iterate through the matrix (using a nested for-loop), and push_back every A[i][j] element into the i-th list.
If you're still confused, feel free to post follow-up questions here.
We can do the second part (delete numbers == X) after we figure this out.