
Problem 3. Circular Reference
1 struct DLLNode
2 {
3 std::shared_ptr<DLLNode> prev;
4 std::shared_ptr<DLLNode> next;
5 };
6
7 struct DLL
8 {
9 std::shared_ptr<DLLNode> head {};
10 std::shared_ptr<DLLNode> tail {};
11
12 void push_front(std::shared_ptr<DLLNode>);
13 void push_back(std::shared_ptr<DLLNode>);
14
15 std::shared_ptr<DLLNode> front();
16 std::shared_ptr<DLLNode> back();
17 };
18
Link to godbolt
Run a->next = b
and b->prev = a.
Extra: How to fix?
14 / 26