In this Java program you will implement your own doubly linked lists. Implement the following operations that...

90.2K

Verified Solution

Question

Programming

In this Java program you will implement your own doubly linkedlists.
Implement the following operations that Java7 LinkedLists have.

1. public DList()
This creates the empty list

2. public void addFirst(String element)
adds the element to the front of the list

3. public void addLast(String element)
adds the element to the end of the list

4. public String getFirst()

5. public String getLast()

6. public String removeLast()
removes & returns the last element of the list.

7. public String removeFirst()
removes & returns the front element of the list.

8. public String get(int index)
Returns the value at “position” index. IndexOutOfBoundsExceptionshould be
thrown if the index is non-existent.

9. public String set(int index, String value)
changes the value at “position” index and returns the old value.IndexOutOfBoundsException should be thrown if the index isnon-existent.

10. public int indexOf(Object obj)
Returns the index of obj if it is in the list and -1 otherwise.

11. public int size()

12.public boolean contains(Object obj)
Returns true if obj appears in the list and false otherwise.

13. public Iterator iterator()
Returns an iterator over the list. This should be a non staticinner class.

Answer & Explanation Solved by verified expert
3.8 Ratings (501 Votes)
Hi Doubly linked list implementation code is given below public class DoublyLinkedListImpl private Node head private Node tail private int size public DoublyLinkedListImpl size 0 private class node E element Node next Node prev public NodeE elementNode nextNode prev thiselementelement thisnextnext thisprevprev creates an empty list public Dlist size0 head new DNode nullnullnull create head tail    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