Jun 22, 2024
insertAtPosition
data
and position
position < 0
, throw IllegalArgumentException
: "Invalid position, cannot be negative."position > size
, throw IllegalArgumentException
: "Invalid position, exceeds list size."current
starting from head and a counter to move to the desired node.counter < position - 1
.
current
to next node.current.next
.current
's next to the new node.10
, Size: 110 -> 12
, Size: 210 -> 12 -> 15
, Size: 310 -> 12 -> 25 -> 15
, Size: 4End of Lecture Notes