 |
Exercise Sheet 6: Cycling to Work
Linked Implementation of a Stack
You can find an animated linked implementation of a
Stack ADT that you can try out at here.
Write a recursive (linked) implementation of a Stack of
characters, called StackCharLinked. Your stack
should implement the DAT.StackChar interface (that
is, the StackChar interface in the
DAT package).
Note that while the interface allows for an
Overflow exception to be thrown by the push
method, this has been included for the block representation, and there
is no need for your linked implementation to throw one.
Hint: Look back at the basic linked list class
covered in the DSA Notes. The Stack uses a similar
structure. (Use appropriate variable names for the stack however.)
Write a test program that tries out each operation to
satisfy yourself that you stack works correctly.
-
Basic Performance Comparisons
Topic 6 of the DAT Notes introduces a basic method of performance
analysis for ADT operations using some simple timing assumptions.
Carry out a basic performance analysis of your two Stack
implementations. Under what conditions do the operations
have constant time performance?
-
Counting while Cycling
In an earlier exercise you implemented a cyclic queue of strings
using indices to the first and last items. As discussed in the DAT
Notes, this requires increasing the size of the block in order to
differentiate between an empty queue and a full queue.
An alternative solution suggested in the Notes was to keep
an index to the first item, along with a variable, say
count, that stores the current size of (number
of items in) the queue. Thus, for example, when an item is
inserted, the count will increase by 1.
DAT Spot Check
You should submit your QueueCharCyclic code for
checking.
[3 Lab Marks]
Unbounded Cycling
An (unbounded) queue can be implemented cyclically based
on a linked list - rather than referencing "null", the last item's
successor references the beginning of the queue. While this is not
necessary to prevent erosion, it does mean that rather than having
references to the beginning and the end of the queue, only a
single reference is needed.
|
 |