Insert node in a Linked List
EasyYou're given the following 2 inputs:
- The
data
for a new node to be inserted in a singly linked list. - The node
left_node
that the new node should be inserted after.
Write a function that inserts the new node after the
left_node
in its singly linked list.For example, let's use the following linked list as an example:
(1) -> (5) -> (7) -> (2)
If your function is passed the data
8
and the third node in the above list with the data 7
, the linked list should become:(1) -> (5) -> (7) -> (8) -> (2)
Assume that the input
left_node
can be any node in the list..Try it first
Solution
8 Essential Linked Lists Coding Interview Problems
Master Linked Lists by trying the coding challenges below.
- 1.Insert NodeEasy
- 2.Remove NodeEasy
- 3.Find the MiddleEasy
- 4.Add Linked ListsEasy
- 5.Reverse Linked ListMedium
- 6.Detect CycleMedium
- 7.Merge Linked ListsMedium
- 8.Pivot Linked ListHard