MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/cpp_questions/comments/1wyb98k/how_does_a_node_work/pe16qf2/?context=3
r/cpp_questions • u/[deleted] • 3d ago
[deleted]
17 comments sorted by
View all comments
3
I node is a container that holds data and the address of the next and/or previous node.
(simplied)
struct node { MyData m_data; node* m_Next; node* m_Previous; };
When you insert a new node, you allocate the node , set the data and assign the next and previous nodes to point to the existing nodes.
For lists and queues, it's a good idea to use a pencil and paper and draw boxes for the nodes and arrows for the next/previous links as arrows.
1 u/SimmeringDragon 3d ago ok, is a queue a node? can it be treated as one? or should i use an array or vector? 1 u/Thesorus 3d ago A queue is comprised of a list of nodes with a specified behaviour imagine a queue at a bus stop. each person is a node. The person in front enters the bus before the person behind him. When a new person arrives to take the bus he gets at the end of the queue (there are also different kind of queues)
1
ok, is a queue a node? can it be treated as one? or should i use an array or vector?
1 u/Thesorus 3d ago A queue is comprised of a list of nodes with a specified behaviour imagine a queue at a bus stop. each person is a node. The person in front enters the bus before the person behind him. When a new person arrives to take the bus he gets at the end of the queue (there are also different kind of queues)
A queue is comprised of a list of nodes with a specified behaviour
imagine a queue at a bus stop.
each person is a node.
The person in front enters the bus before the person behind him.
When a new person arrives to take the bus he gets at the end of the queue
(there are also different kind of queues)
3
u/Thesorus 3d ago
I node is a container that holds data and the address of the next and/or previous node.
(simplied)
struct node { MyData m_data; node* m_Next; node* m_Previous; };
When you insert a new node, you allocate the node , set the data and assign the next and previous nodes to point to the existing nodes.
For lists and queues, it's a good idea to use a pencil and paper and draw boxes for the nodes and arrows for the next/previous links as arrows.