Suppose you are implementing a doubly linked list data structure in Java, where each Node in the list maintains two Node
Posted: Thu May 05, 2022 1:21 pm
Suppose you are implementing a doubly linked list data structure
in Java, where each Node in the list maintains two Node
references, prev and next, to refer to adjacent
items in the list. Based on the code given, add a new instance
method called removeAt, which takes an integer parameter,
removes the node which is that many steps from the front of the
list, and returns the Item deleted. Be sure to account
for special cases, such as empty lists and invalid parameter
values.
Starter code:
public class LinkedList<Item> {
private int size;
private Node<Item> first;
private static class Node<Item> {
Item item;
Node<Item> next;
Node<Item> prev;
}
// Write your method below. You may not call any helper
methods. Preserve code formatting.
// Assume the rest of the class works correctly (not
shown).
}
in Java, where each Node in the list maintains two Node
references, prev and next, to refer to adjacent
items in the list. Based on the code given, add a new instance
method called removeAt, which takes an integer parameter,
removes the node which is that many steps from the front of the
list, and returns the Item deleted. Be sure to account
for special cases, such as empty lists and invalid parameter
values.
Starter code:
public class LinkedList<Item> {
private int size;
private Node<Item> first;
private static class Node<Item> {
Item item;
Node<Item> next;
Node<Item> prev;
}
// Write your method below. You may not call any helper
methods. Preserve code formatting.
// Assume the rest of the class works correctly (not
shown).
}