Templates to Define ADTs

In the discussion of ADTs above, the examples were generalized by using typedef to indicate the data type of the stacks and the queues. It is also possible to use templates to generalize these ADTs. For example using arrays as the basis for the ADT, see date.h, templateStack.h and useTemplateStack.cpp as a way to use templates for stacks. Using date.h and the following two files: templateQueue.h and useTemplateQueue.cpp, the generalized queue discussed above using typedef can be generalized even further using templates seen in this example.

The template examples just considered were based upon arrays that have a limited size. However these examples may be changes so that both the template stacks and the template queues are based upon linked lists. For an example of a template stack based upon linked lists see: templateStackList.cpp and templateStackList.h. For an example of a template queue based upon a linked list see: templateQueueList.cpp and templateQueueList.h.

Intermediate Business Programming with C++
Intermediate Business Programming with C++
ISBN: 738453099
Year: 2007
Pages: 142

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net