I am learning linked list in c and c++ however I am stuck trying to understand why the prev and next pointer data types are nodes. Could you please explain to me why it is a node pointer rather one of the predefined data types?
Asked
Active
Viewed 318 times
-3
-
2What predefined data types did you have in mind? Pointers are generally the "links" in a linked list. – WhozCraig Feb 27 '22 at 14:46
-
1The prev and next pointers are just links to the previous and next nodes respectively. – The Coding Fox Feb 27 '22 at 14:47
-
You can have a pointer to a class or struct the same way you can have a pointer to an int or a float – drescherjm Feb 27 '22 at 15:00
1 Answers
1
So you have a node. You ask "Who's next behind you?", and it points to the node behind him.
Now you want to ask that thing who's next behind them, but you can only do so if they are a node with that .next()
(or similar) method, which points to the next. If it were an int, it couldn't do that.
So you need nodes as wrappers around whatever it is you want to store, in order to navigate through the linked list.

LucasFA
- 33
- 4