This exercise consists of two parts:
A. Prepare a minimal version of your class IntList from last semester's class Programming 1.
B. Use this new version IntlistMinimal as the basis for implementing the classes IntStack and Int Queue.
Part A in detail:
You may use your solution for exercise 5 from last semester. If you did not do exercise 5 last semester, then you must implement the following new version of IntList.
The class IntListMinimal is a minimal implementation of the abstract data structure "list" for integer values.
Implement the class IntListMinimal according to the following specification.
IntListMinimal (int maxlength) // Maxlength is the maximum number of elements in the list
void append (int value) // Value is appended to the list (becomes the last element in the list).
void clear () // All elements are deleted from the list.
void deleteFirst () // The first element of the list is deleted.
void deleteLast () // The last element of the list is deleted.
void display () // The values in the list are displayed.
int get (int index) // The value at index is returned.
int getCount () // The current count (number of values) is returned.
void insertFirst (int value) // Value is inserted at the first position in the list.
You should handle any errors by displaying an appropriate message (use System.out.println).
During implementation you may notice issues not mentioned in the above specification. Solve these isssues as you see fit and be prepared to defend your decisions.
The first element in the list is at index = 0 (not 1).
Part B in detail:
Here are the methods for the class IntQueue:
class IntQueue {
IntQueue (int
maxlength)
void enqueue (int
value) // adds value to the queue
int dequeue() //
removes and returns the first value in the queue
}
First, implement the class IntQueue as subclass of the class IntListMinimal. Your class IntQueue is thus derived from IntListMinimal.
Second, implement the class IntQueue using a variable of type IntListMinimal. Your class IntQueue is thus derived only from the basic Java class Object, and not from IntListMinimal.
Here are the methods for the class IntStack:
class IntStack {
IntStack (int
maxlength)
void push (int
value) // puts value on top of the stack
int pop() //
removes and returns the top value on the stack
}
First, implement the class IntStack as subclass of the class IntListMinimal. Your class IntStack is thus derived from IntListMinimal.
Second, implement the class IntStack using a variable of type IntListMinimal. Your class IntStack is thus derived only from the basic Java class Object, and not from IntListMinimal.
Implement a test program for each class. Be sure to test at the limits, for example, lists with just one element or inserting the last element. Each method should be tested by a dedicated test method. Be sure to test your error handling.
Notes:
Your implementation of IntListMinimal must use only one int[] to hold the integer values.