Write a class LinkedStack that
implements a stack using a linked list. It should have these members:
LinkedStack()
void push(int i)
int pop()
bool isEmpty { get; }
Write a class UniqueStack that
subclasses LinkedStack, and ignores any
attempt to push the same value that is at the top of the stack.
Write a class DynArray representing a
dynamic (i.e. resizable) array of integers. It should have these
members:
DynArray()
Create a new DynArray that is initially empty.
DynArray(int length)
Create a new DynArray with the given initial length. All elements will be 0.
DynArray(int length, int val)
Create a new DynArray with the given initial length. All
elements will initially be set to val.
int get(int index)
Retrieve the value at the given index, which must be less than the current array length.
void set(int index, int val)
Set the value at the given index, which must be less than the current array length.
void add(int i)
Append a new element to the array, growing its length by 1.
int length { get; set; }
Get or set the length of the array. When growing the array, all new elements will be 0.
Write a class AutoArray that
subclasses DynArray. It should have a
single constructor:
AutoArray(int defaultVal)
Create an empty AutoArray
with the given default value.
An AutoArray is like a DynArray,
except that
Retrieving any element past the end of the array will return the array's default value rather than crashing.
Setting any element past the end of the array will automatically extend the array length as needed. Any new elements will be initialized to the array's default value.
Write a class LinkedQueue that
implements a queue using a linked list. It should have the following
members:
LinkedQueue()
void enqueue(int i)
int dequeue()
bool isEmpty { get; }
Write a class ArrayQueue that
implements a queue using a circular array. The queue should have no
size limit. The class should have these members:
ArrayQueue()
void enqueue(int i)
int dequeue()
bool isEmpty { get; }