Reputation: 115
Is anyone familiar with before* and after* pointers when using a doubly linked list with two dummy nodes in c++? I am trying to account for all the special cases of insertions (empty list, insert at very front, insert at very back, insert in the middle) using a before* and after* as my iterators.
How do you correctly use the before* and after* to determine where to insert?
Any feedback is greatly appreciated. Thanks in advance.
Upvotes: 0
Views: 357
Reputation: 182753
With two dummy nodes, there are no special cases. Since you always have a dummy node in front and a dummy node at the end, you never operate on an empty list. You never insert at the very front. You never insert at the very back. All insertions and deletions are in the middle -- that's the point of the two sentinel nodes.
Upvotes: 2