The double-edged box is a node.
The single-lined arrows are pointers.
╔═════╗
║ ╟──► next
prev ◄──╢ ║
╚═════╝ |
In a doubly-linked list, the first node’s prev pointer will have the address
nullptr, and the last node’s next pointer will also have the address
nullptr.
When two nodes are connected, the first’s next pointer will have the address of the second node. Likewise, the second’s prev pointer will have the address of the first node.
╔═════╗ ╔═════╗
║ ╟──►║ ╟──► nullptr
nullptr ◄──╢ ║◄──╢ ║
╚═════╝ ╚═════╝ |
In this way, you can traverse all the nodes forward by following the next pointer of each node. Likewise, you can find all nodes going backward by following the prev pointers.
In a
circular list, the difference is that there are no
nullptr pointers; the list wraps around. The beginning (or head) of the list is considered the first node in the list, even though it is a circle.
Here is a list of eight nodes containing the numbers 1, 2, 3, …, 8:
List.size = 8
List.head
↓
╔═════╗ ╔═════╗ ╔═════╗
║ 8 ╟──►║ 1 ╟──►║ 2 ║
║ ║◄──╢ ║◄──╢ ║
╚═══╤═╝ ╚═════╝ ╚═══╤═╝
▲ ▼ ▲ ▼
╔═╧═══╗ ╔═╧═══╗
║ 7 ║ ║ 3 ║
║ ║ ║ ║
╚═══╤═╝ ╚═══╤═╝
▲ ▼ ▲ ▼
╔═╧═══╗ ╔═════╗ ╔═╧═══╗
║ 6 ╟──►║ 5 ╟──►║ 4 ║
║ ║◄──╢ ║◄──╢ ║
╚═════╝ ╚═════╝ ╚═════╝ |
Notice that, if you
push a new node in “front” of the head node, it will go between 1 and 8, and the head pointer will be updated to reflect the change. Here, we “push” a new node with the value = 100:
List.size = 9
List.head (used to be the head)
↓ ↓
╔═════╗ ╔═════╗ ╔═════╗ ╔═════╗
║ 8 ╟──►║ 100 ╟──►║ 1 ╟──►║ 2 ║
║ ║◄──╢ ║◄──╢ ║◄──╢ ║
╚═══╤═╝ ╚═════╝ ╚═════╝ ╚═══╤═╝
▲ ▼ ↑ ▲ ▼
╔═╧═══╗ (new node) ╔═╧═══╗
║ 7 ║ ║ 3 ║
║ ║ ║ ║
╚═══╤═╝ ╚═══╤═╝
▲ ▼ ▲ ▼
╔═╧═══╗ ╔═════╗ ╔═╧═══╗
║ 6 ╟───────►║ 5 ╟───────►║ 4 ║
║ ║◄───────╢ ║◄───────╢ ║
╚═════╝ ╚═════╝ ╚═════╝ |
The new node with value 100 was inserted between the head node and the last node in the circle. Then the head was changed to point to the new head.
Get used to seeing diagrams like this, especially when talking about pointers and linked lists and the like.
Hope this helps.