Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please design SpecializedList including SListNode based on the starter code provided. //---------------------------------------------------------------------------- // SpecializedListInterface. // // Interface for a class that implements a list of

Please design SpecializedList including SListNode based on the starter code provided.

image text in transcribed

//---------------------------------------------------------------------------- // SpecializedListInterface. // // Interface for a class that implements a list of bytes // There can be duplicate elements on the list // The list has two special properties called the current forward position // and the current backward position -- the positions of the next element // to be accessed by getNextItem and by getPriorItem during an iteration // through the list. Only resetForward and getNextItem affect the current // forward position. Only resetBackward and getPriorItem affect the current // backward position. Note that forward and backward iterations may be in // progress at the same time //----------------------------------------------------------------------------

package a1;

public interface SpecializedListInterface {

public void resetForward(); // Effect: Initializes current forward position for this list // Postcondition: Current forward position is first element on this list

public byte getNextItem (); // Effect: Returns the value of the byte at the current forward // position on this list and advances the value of the // current forward position // // Preconditions: // - Current forward position is defined // - There exists a list element at current forward position // - No list transformers (i.e. insertion methods) have been called // since the most recent call of getNextItem; and if list transformer calls // have been made since the most recent call of getNextItem, // or getNextItem has never been called on the list, // then a call must be made to resetForward before calling getNextItem. // // Postconditions: // - Return value = (value of byte at current forward position) // - If current forward position is the last element then // current forward position is set to the beginning of this // list, otherwise it is updated to the next position

public void resetBackward(); // Effect: Initializes current backward position for this list // Postcondition: Current backward position is last element on this list

public byte getPriorItem (); // Effect: Returns the value of the byte at the current backward // position on this list and advances the value of the // current backward position (towards front of list) // // Preconditions: // - Current backward position is defined // - There exists a list element at current backward position // - No list transformers (i.e. insertion methods) have been called // since the most recent call of getPriorItem; and if list transformer calls // have been made since the most recent call of getPriorItem, // or getPriorItem has never been called on the list, // then a call must be made to resetBackward before calling getPriorItem. // // Postconditions: // - Return value = (value of byte at current backward // position) // - If current backward position is the first element then // current backward position is set to the end of this list; // otherwise, it is updated to the prior position

public int lengthIs(); // Effect: Determines the number of elements on this list // Postcondition: Return value = number of elements on this list public void insertFront (byte item); // Effect: Adds the value of item to the front of this list // PostCondition: Value of item is at the front of this list public void insertEnd (byte item); // Effect: Adds the value of item to the end of this list // PostCondition: Value of item is at the end of this list }

The lists must hold elements of the primitive type byte; duplicate elements are allowed. The only list operations that we will use, are the lengthIs operation and the iterator operations. We are going to need to process elements from left-to-right and from right-to-left, so we need to support two iterators. In addition, we are going to need to insert items at the front and at the back of our lists. Please take sometime to read the starter code. You must provide an implementation of the given interface. Please name your implementation SpecializedList. You will need to design a helper class called SListNode. Please see the following image for some examples

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Shamkant B. Navathe

7th Edition Global Edition

1292097612, 978-1292097619

More Books

Students also viewed these Databases questions