Implement a singly linked list ADT to store a collection of doubles. Part - 2: I
ID: 3856660 • Letter: I
Question
Implement a singly linked list ADT to store a collection of doubles. Part - 2: Implement a Double linked List ADT to store a collection of integers. (You are allowed to extend the demo code posted on GitHub for this homework). Make sure to provide an interactive user interface to test these new functions in the main() for grader. Your ADT will include the following member functions: ---a default constructor ---the "big-3": destructor, copy constructor and overloaded assignment operator 1. a member function pushFront(data) that inserts a node with data at the front of the list 2. a member function pushBack(data) that appends a node with data at the back of the list 3. a member function popFront() that removes first node of the list. 4. a member function popBack() that removes last node of the list. 5. a member function insert(index, val) that inserts a new node with value "val" at a specific position mentioned by the index argument. 6. a member function deleteDuplicates(val) that deletes a node with that number and all its copies from the list, where these copies can be located anywhere in the list. 7. a member function mtoLastElement(M) that returns Mth to the last element of a list such that when M = 0, the last element of the list is returned. 8. a member function size() that returns the size of the list. 9. an overloaded put operator (Explanation / Answer
import java.util.*;
public class Test
{
public static void main(String args[])
{
// Creating object of class linked list
LinkedList<String> object = new LinkedList<String>();
// Adding elements to the linked list
object.add("A");
object.add("B");
object.addLast("C");
object.addFirst("D");
object.add(2, "E");
object.add("F");
object.add("G");
System.out.println("Linked list : " + object);
// Removing elements from the linked list
object.remove("B");
object.remove(3);
object.removeFirst();
object.removeLast();
System.out.println("Linked list after deletion: " + object);
// Finding elements in the linked list
boolean status = object.contains("E");
if(status)
System.out.println("List contains the element 'E' ");
else
System.out.println("List doesn't contain the element 'E'");
// Number of elements in the linked list
int size = object.size();
System.out.println("Size of linked list = " + size);
// Get and set elements from linked list
Object element = object.get(2);
System.out.println("Element returned by get() : " + element);
object.set(2, "Y");
System.out.println("Linked list after change : " + object);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.