In java
1. Write a sequence of commands that will remove the tail of a doubly linked list.
Using a linked list with 3 nodes, draw what happens to the list as each line executes when you remove the tail.
2. Write a sequence of commands that will add a new item to index 0 of a doubly linked list.
Using a linked list with 3 nodes, draw what happens to the list as each line executes.
1)
if(head == null) {
return;
}
if (head != tail) {
tail = tail.prev;
tail.next = null;
} else {
head = tail = null;
}
2)
Node newNode = new Node(value);
newNode.next = head;
newNode.prev = null;
if (head != null)
head.prev = newNode;
head = newNode;
Get Answers For Free
Most questions answered within 1 hours.