Logo Data Structures and Algorithms with Object-Oriented Design Patterns in C++
next up previous contents index

Exercises

    1. How much space does the Array<T> class declared in Program gif use for an array of integers of length N?
    2. How much space does the LinkedList<T> class declared in Program gif use to store a list of n integers?
    3. For what value of N/n do the two classes use the same amount of space?
  1. The array subscripting operators defined in Program gif only test whether tex2html_wrap_inline61255, the do not test whether tex2html_wrap_inline61257. Explain why the second test is not required in this implementation.
  2. The SetBase member function of the Array<T> class defined in Program gif simply changes the value of the base member variable. As a result, after the base is changed, all the array elements appear to have moved. How might the routine be modified so that the elements of the array don't change their apparent locations when the base is changed?
  3. Write the C++ code for the assignment operator of the Array<T> class declared in Program gif.
  4. Which routines are affected if we drop the tail member variable from the LinkedList<T> class declared in Program gif? Determine new running times for the affected routines.
  5. How does the implementation of the Prepend function of the LinkedList<T> class defined in Program gif change when a circular list with a sentinel is used as shown in Figure gif (c).
  6. How does the implementation of the Append function of the LinkedList<T> class defined in Program gif change when a circular list with a sentinel is used as shown in Figure gif (c).
  7. Consider the assignment operator for the LinkedList<T> class given in Program gif. What is the purpose of the test &linkedlist != this on line 15?
  8. Equation gif is only correct if the subscript ranges in each dimension start at zero. How does the formula change when each dimension is allowed to have an arbitrary subscript range?
  9. The alternative to row-major layout of of multi-dimensional arrays is called column-major order . In column-major layout the leftmost subscript expression increases fastest. For example, the elements of the columns of a two-dimensional matrix end up stored in contiguous memory locations. Modify Equation gif to compute the correct address for column-major layout.
  10. We wish to add an operator+ member function to the Matrix<T> class declared in Program gif that does the usual matrix addition. Write the C++ code for this member function.

next up previous contents index

Bruno Copyright © 1997 by Bruno R. Preiss, P.Eng. All rights reserved.