Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Node class: public class Node { /** The element stored at this node */ private E element; // reference to the element stored at this

image text in transcribed

Node class:

public class Node { /** The element stored at this node */ private E element; // reference to the element stored at this node /** A reference to the subsequent node in the list */ private Node next; // reference to the subsequent node in the list /** * Creates a node with the given element and next node. * * @param e the element to be stored * @param n reference to a node that should follow the new node */ public Node(E e, Node n) { element = e; next = n; } // Accessor methods /** * Returns the element stored at the node. * @return the element stored at the node */ public E getElement() { return element; } /** * Returns the node that follows this one (or null if no such node). * @return the following node */ public Node getNext() { return next; } // Modifier methods /** * Sets the node's next reference to point to Node n. * @param n the node that should follow this one */ public void setNext(Node n) { next = n; } } 
1) In this lab, you will write generic DoublyLinkedList class. DoublyLinkedList will contain DoublyNode E> objects which is given for you in piazza The class will contain the methods below: -head:Node -size:int II head node of the list (or null if empty) II last node of the list (or null if empty) Il number of nodes in the list +DoublyLinkedList) Il constructs an initially empty list +size():int +isEmpty0:boolean Tests whether the linked list is empty +first():E +last():E +addFirst(E):void lIAdds an element to the front of the list. +addLast(E):void l/Adds an element to the end of the list. +removeFirst)E I/Removes and returns the first element of the list. +removeLast):E I/Removes and returns the last element of the list. +equals(Object):boolean Ilyou will overwrite Object class' equals method and you wil check if two SinglyLinkedList object is equal or not. /Returns the number of elements in the linked list. WReturns (but does not remove) the first element of the list I/Returns (but does not remove) the last element of the list. +toString):String //Produces a string representation of the contents of the list. +addBetween(E, DoublyNode):void Adds an element to the linked list in between the given nodes.The given predecessor and successor should be neighboring each other prior to the call. +remove(DoublyNode):E element. I/Removes the given node from the list and returns its +toString):String IProduces a string representation of the contents of the list. 2) Test all the methods in main class 3)Sort a DoublyLinkedList object. If E is String, sort elements according to alphabetical order. If E is Integer sort increasing order. (Hint: use Comparable interface.)

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: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Graph Database Modeling With Neo4j

Authors: Ajit Singh

2nd Edition

B0BDWT2XLR, 979-8351798783

More Books

Students also viewed these Databases questions