Question: IN JAVA Write a class called GenCircularLinkedList which is a generic circular linked list. This link list is similar to the single linked list that

IN JAVA

Write a class called GenCircularLinkedList which is a generic circular linked list. This link list is similar to the single linked list that was shown in class except the last elements link points to the first element. In other words the tail points to the head.

The class GenCircularLinkedList needs to have the following:

Internal class ListNode which hasInstance Variables

data of type T

link of type ListNode

Constructors

Default

Parameterized

Instance Variables

head of type ListNode which always points to the beginning of the linked list

current of type ListNode which moves around pointing to one of the nodes

previous of type ListNode which is one element behind the current

tail of type ListNode which is the last element in the list thats link points to head

Constructor

A default constructor that initializes head to an empty ListNode and sets current to point at the head.

Methods

goToNext This moves the current node forward in the list by one node.

goToPrev This moves the current node backwards in the list by one node.

getDataAtCurrent returns the data at the current node as long as the current isnt null

setDataAtCurrent takes in a parameter and sets the data at the current node to that value as long as current is not null

insert: This creates a new ListNode and adds it after the tail. Keep in mind the list must remain circular.

insertNodeAfterCurrent creates a new ListNode based on data that is passed in by a parameter and puts that node after the current position. Keep in mind that if the current node is either head or tail you need to make sure to set the proper links correctly.

deleteCurrentNode removes the current node from the list by resetting the links. Keep in mind that if the current node is either the head or tail then theres some special steps that must be performed.

showList prints out the contents of the list line-by-line

inList returns a true or false value based on whether or not the data passed in via a parameter is in the list

Finally write a class that tests the functionality of a circular linked list.

Example Dialog:

Circular Linked List Tester

Create, insert, and print test by adding values 1-4

1

2

3

4

Moving current twice and deleting the current

1

2

4

Testing In list by searching for the value 4

true

Testing In list by searching for the value 3

false

Testing getting and setting current by adding the value 10 to the current data.

1

2

14

Moving current forward and deleting that node

2

14

Moving current backwards and deleting that node

2

Test Done

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!