Modify the class linkedlistnbspto make it a doubly linked


Exercise 1: Implementing a Doubly Linked List

Modify the class LinkedList to make it a doubly linked list. Name your class DoublyLinkedList. Add a method addEnd to add an integer at the end of the list and a method displayInReverse to print the list backwards:

voidaddEnd(int x): create this method to add x to the end of the list. 
voiddisplayInReverse(): create this method to display the list elements from the last item to the first one. 

Create a main class to test your DoublyLinkedList class. 

Exercise 2: Using a Doubly Linked List

Using the class DoublyLinkedList completed in the previous exercise, write a program to store all the prime numbers up to 100 in a DoublyLinkedList object. The numbers should be stored in such a way that when "display" is invoked, the listing will be shown in increasing order: 2, 3, 5, 7, 11, 13, 17, ... .

Exercise 3: Implementing a Bag Class

Create a class bag that uses a linked list to store the bag items. The item type must be a Java String type, that is, the bag will store strings of characters. The class should have the methods listed below. Create a main class to test your bag class. This main class should fill a bag with the keywords of the Java language.

  1. . Bag(): default constructor
  2. booleanisEmpty(): determines whether the bag is empty
  3. void print(): prints the bag elements
  4. intgetLength(): returns the number of items in the bag
  5. void clear(): removes all of the items from the bag
  6. void add(String item): adds an item to the bag
  7. voidremoveOne(String item): removes an item from the bag; only one occurrence of the item should be removed.

  int count(String item): counts the number of occurrences of an item in the bag. 

(Note that you can reuse the code in Exercise 1 for the LinkedList class to create your bag class. It will help you to save development time.) 

Attachment:- text.txt

Solution Preview :

Prepared by a verified Expert
Basic Computer Science: Modify the class linkedlistnbspto make it a doubly linked
Reference No:- TGS01117322

Now Priced at $60 (50% Discount)

Recommended (90%)

Rated (4.3/5)