Doubly linked lists are useful for more than just inserting and removing elements from the head and tail of the list. They can maintain a list of elements that allows for insertion and removal to the interior of the list
Given a node
of a doubly linked list (which is currently followed by
), we want to insert a new node
immediately after
. Concretely, we want to write a functioninsert(v)
which takes a node,
, and inserts a new node after
. The result should be a list where
'snext
points to
,
'snext
points to
,
'sprev
points to
, and
'sprev
points to
.
If we execute these events in the wrong order, we can erase crucial information that will break the list. How should the following steps be ordered so that they correctly insert a node in-the middle of a doubly linked list?
prev
point to
.next
point to
.prev
point to
.next
point to
.Consider a circularly linked list. Which of the following methods below removes the node after the cursor? The cursor is a special node which allows us to have a place to start from if we ever need to traverse a circularly linked list.
1 2 3 4 5 6 7 8 9 10 11 |
|
1 2 3 4 5 |
|
1 2 3 4 5 6 7 8 9 10 11 |
|
1 2 3 4 5 6 7 8 9 10 11 |
|
Given a singly linked list, write a program the shifts every node unit to the left.
For example
When4 6 8 9is shifted units left it becomes8 9 4 6
What will the following linked list look like when each node is shifted to the left.
34 17 17 74 83 59 39