Stage 1 · Code
Linked Lists
Doubly Linked List
Bidirectional traversal with prev/next pointers.
5 min readMastering Data Structures & Algorithms for Software Engineering InterviewsCode
Node Structure
A doubly linked list node has both Next and Prev pointers. The list maintains both Head and Tail pointers, enabling O(1) operations at both ends.
Godoubly-linked-list-structure.go
16 linesLn 1, Col 1Go
Each node links forward and backward. Head.Prev = nil, Tail.Next = nil. Size tracked for O(1) length.
Operations
Godoubly-linked-list-operations.go
40 linesLn 1, Col 1Go
AddFirst/AddLast are O(1) with tail pointer. Remove requires updating both Prev and Next pointers of neighbors. Handle edge cases: removing head/tail.
Use Cases
- LRU Cache: Move accessed node to front (O(1) with DLL + hashmap).
- Deque: Double-ended queue with O(1) push/pop both ends.
- Undo/Redo: Navigate history bidirectionally.
- Playlist/Music queue: Previous/next track navigation.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.