Answered step by step
Verified Expert Solution
Question
1 Approved Answer
/ * * * Your implementation of a CircularSinglyLinkedList without a tail pointer. * * @author YOUR NAME HERE * @version 1 . 0 *
Your implementation of a CircularSinglyLinkedList without a tail pointer.
@author YOUR NAME HERE
@version
@userid YOUR USER ID HERE ie gburdell
@GTID YOUR GT ID HERE ie
Collaborators: LIST ALL COLLABORATORS YOU WORKED WITH HERE
Resources: LIST ALL NONCOURSE RESOURCES YOU CONSULTED HERE
public class CircularSinglyLinkedList
Do not add new instance variables or modify existing ones.
private CircularSinglyLinkedListNode head;
private int size;
Do not add a constructor.
Adds the data to the specified index.
Must be O for indices and size and On for all other cases.
@param index the index at which to add the new data
@param data the data to add at the specified index
@throws java.lang.IndexOutOfBoundsException if index or index size
@throws java.lang.IllegalArgumentException if data is null
public void addAtIndexint index, T data
Adds the data to the front of the list.
Must be O
@param data the data to add to the front of the list
@throws java.lang.IllegalArgumentException if data is null
public void addToFrontT data
Adds the data to the back of the list.
Must be O
@param data the data to add to the back of the list
@throws java.lang.IllegalArgumentException if data is null
public void addToBackT data
Removes and returns the data at the specified index.
Must be O for index and On for all other cases.
@param index the index of the data to remove
@return the data formerly located at the specified index
@throws java.lang.IndexOutOfBoundsException if index or index size
public T removeAtIndexint index
Removes and returns the first data of the list.
Must be O
@return the data formerly located at the front of the list
@throws java.util.NoSuchElementException if the list is empty
public T removeFromFront
Removes and returns the last data of the list.
Must be On
@return the data formerly located at the back of the list
@throws java.util.NoSuchElementException if the list is empty
public T removeFromBack
Returns the data at the specified index.
Should be O for index and On for all other cases.
@param index the index of the data to get
@return the data stored at the index in the list
@throws java.lang.IndexOutOfBoundsException if index or index size
public T getint index
Returns whether or not the list is empty.
Must be O
@return true if empty, false otherwise
public boolean isEmpty
Clears the list.
Clears all data and resets the size.
Must be O
public void clear
Removes and returns the last copy of the given data from the list.
Do not return the same data that was passed in Return the data that
was stored in the list.
Must be On
@param data the data to be removed from the list
@return the data that was removed
@throws java.lang.IllegalArgumentException if data is null
@throws java.util.NoSuchElementException if data is not found
public T removeLastOccurrenceT data
Returns an array representation of the linked list.
Must be On for all cases.
@return the array of length size holding all of the data not the
nodes in the list in the same order
public T toArray
Returns the head node of the list.
For grading purposes only. You shouldn't need to use this method since
you have direct access to the variable.
@return the node at the head of the list
public CircularSinglyLinkedListNode getHead
DO NOT MODIFY!
return head;
Returns the size of the list.
For grading purposes only. You shouldn't need to use this method since
you have direct access to the variable.
@return the size of the list
public int size
DO NOT MODIFY!
return size;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started