help with linked lists and matrix

ok so i have matrix (random numbers)
A[M][N] = { {5, 18, 32, 87},
{11, 76, 32, 12},
{54, 47, 32, 90},
{12, 7, 32, 99} }; (M is 5, N is 4)

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

Then i need to create int X, check lists and delete numbers == X
.
Last edited on
Here's a start:
1
2
3
4
5
6
7
8
9
10
const std::size_t SIZE{ 4 };

class Node
{
	int data[SIZE];
	Node* next;

public:
	
};
Dont send Sakurawhatever a private message.

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.
Last edited on
@Arslanwhatever
What is wrong? Are you mad at me?
Not intended to make it off-topic though.

Edit : Your instructions are fairly useless, if the OP does not respond.
Last edited on
Hey so i need more help, i'm like begginer in c++, especially in lists (never used lists before!!) :)

@integralfx
We can use classes? I know for the structures.. Guessing it's the same thing

@Arslan7041
I get the second part, but not the first
@varnica
Can you at least give us some efforts? (even your function main is okay).

We can use classes? I know for the structures.. Guessing it's the same thing

Classes are exactly the same as structures, except in classes the default access specifier is private, while in structures it is public.
I just declared 2d array in main, because i've never used linked links, i know how they work in theory :)
Topic archived. No new replies allowed.