(Implement a doubly linked list) The MyLinkedList class used in Listing 24.5 is a one-way directional...

60.1K

Verified Solution

Question

Programming

(Implement a doubly linked list) The MyLinkedList class used inListing 24.5 is a one-way directional linked list that enablesone-way traversal of the list. Modify the Node class to add the newdata field name previous to refer to the previous node in the list,as follows

: public class Node {

E element;

Node next;

Node previous;

public Node(E e) {

element = e; } }

Implement a new class named TwoWayLinkedList that uses a doublylinked list to store elements. Define TwoWayLinkedList toimplements MyList. You need to implement all the methods defined inMyLinkedList as well as the methods listIterator() andlistIterator(int index). Both return an instance ofjava.util.ListIterator (see Figure 20.4). The former sets thecursor to the head of the list and the latter to the element at thespecified index..

Answer & Explanation Solved by verified expert
4.2 Ratings (518 Votes)
Try this approach to solve this task import javautilIterator public class Exercise03 public static void mainString args MyTwoWayLinkedList list new MyTwoWayLinkedList listaddasdf listadd1234 listaddfffff listadd44556699 listadd1234 listaddccsdcd listadd1234 listadd1234sssss Systemoutprintlnlist listremove3 Systemoutprintlnlist listremoveLast Systemoutprintlnlist Systemoutprintlnlistcontainsasd Systemoutprintlnlistcontainsfffff Systemoutprintln Systemoutprintlnlistget3 Systemoutprintlnlistget5 Systemoutprintln SystemoutprintlnlistindexOf44556699 SystemoutprintlnlistindexOfasdf SystemoutprintlnlistindexOf123 SystemoutprintlnlistindexOf1234 Systemoutprintln SystemoutprintlnlistlastIndexOf44556699 SystemoutprintlnlistlastIndexOf1234 SystemoutprintlnlistlastIndexOf1234sssssssss Systemoutprintln Systemoutprintlnlistset0 987654321 Systemoutprintlnlistset5 tratata Systemoutprintlnlist for Iterator iterator listiterator iteratorhasNext iteratorremove Systemoutprintlnlist class MyTwoWayLinkedList extends MyAbstractList private Node head tail Create a default list public    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students