Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement the method remove(int from, int to) for the class LinkedList. This instance method removes all the elements in the specified range from this list

image text in transcribed

image text in transcribed

Implement the method remove(int from, int to) for the class LinkedList. This instance method removes all the elements in the specified range from this list and returns a new list that contains all the removed elements, in their original order. The implementation of LinkedList has the following characteristics: An instance always starts off with a dummy node, which serves as a marker for the start of the list. The dummy node is never used to store data. The empty list consists of the dummy node only; In the implementation for this question, the nodes of the list are doubly linked; In this implementation, the list is circular, i e. the reference next of the last node of the list is pointing at the dummy node, the reference previous of the dummy node is pointing at the last element of the list. In the empty list, the dummy node is the first and last node of the list, its references previous and next are pointing at the node itself; Since the last node is easily accessed, because it is always the previous node of the dummy node, the header of the list does not have (need) a tail pointer. Example: if xs is a reference designating a list containing the following elements [a, b, c, d, e, f], after the method call ys = xs remove (2, 3), the list designated by xs contains [a, b, e, f], and ys designates a list containing [c, d]. Write your answer in the class LinkedList on the next page. You cannot use the methods of the class LinkedList. In particular, you cannot use the methods add() or remove(). public class LinkedList {private static class Node {//implementation of the doubly linked nodes private T value; private Node previous; private Node next; private Node(T value, Node previous, Node next) {this, value = value; this. previous = previous; this. next = next;}} private Node head; private int size; public LinkedList () {head = new Node(null, null, null); head. next = head. previous = head; size = 0:} public LinkedList remove(int from, int to) {

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_step_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions