Modify
the result of Exercise 1 from Chapter 13 to use a
TStack
and
TStackIterator
instead
of an array of
Shape
pointers. Add destructors to the class hierarchy so you can see that the
Shape
objects are destroyed when the
TStack
goes out of scope.
Modify
the
Sshape2.cpp
example from Chapter 13 to use
TStack
instead of an array.
Modify
Recycle.cpp
to use a
TStash
instead of a
TStack.
Change
Settest.cpp
to use a
SortedSet
instead of a
set.
Duplicate
the functionality of
Applist.cpp
for the
TStash
class.
You
can do this exercise only if your compiler supports member function templates.
Copy
Tstack.h
to a new header file and add the function templates in
Applist.cpp
as
member
function templates of
TStack.
(Advanced)
Modify the
TStack
class to further increase the granularity of ownership: add a flag to each link
indicating whether that link owns the object it points to, and support this
information in the
add( )
function and destructor. Add member functions to read and change the ownership
for each link, and decide what the
owns
flag means in this new context.
(Advanced)
Modify the
TStack
class so each entry contains reference-counting information (
not
the objects they contain), and add member functions to support the reference
counting behavior.
(Advanced)
Change the underlying implementation of
Urand
in
Sorted.cpp
so it is space-efficient (as described in the paragraph following
Sorted.cpp)
rather than time-efficient.
(Advanced)
Change the
typedef
cntr
from an
int
to a
long
in
Getmem.h
and modify the code to eliminate the resulting warning messages about the loss
of precision. This is a pointer arithmetic problem.
(Advanced)
Devise a test to compare the execution speed of an
SString
created
on the stack versus one created on the heap.