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

List Elements

 

The definitions of the member functions of the ListElement<T> class are given in Program gif. Altogether, there are three functions--a constructor and two accessors.

   program3520
Program: ListElement<T> Class Member Function Definitions

The constructor simply initializes the member variable to the passed values. The running time of the constructor is tex2html_wrap_inline61025, where tex2html_wrap_inline60965 is the running time of the copy constructor for objects of class T. Assigning a value to the next field takes a constant amount of time.

The two accessor functions, Datum and Next, simply return the values of the corresponding member variables. Clearly, the running times of each of these functions is O(1). Note that if Datum had been defined as returning a T, rather than a reference to T, the assumption of constant running time would not be valid.


next up previous contents index

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