Insert 1 ==> 1
Insert 2 ==> 1<=>2
Insert 3 ==> 1<=>2<=>3
last node's
next to the new node
and link this new node
to the last node
.
1. Create a new node
, which needs to be added at the last.
2. If the head node
is null,then return this new node
as the head node
.
3. Else, traverse to the end of the list
and assign the new node
to the next
of last node
.
4. Assign the last node
to new node's previous
and it's next
to null
.
public DoublyLinkedNode insertAtTail(DoublyLinkedNode head, int data) { }
C
Java
Python