We will introduce an abstract data type known as a Stack, following closely to the presentation in Ch. 4.2. However, as we begin to examine the C++ code for implementing this concept, we will need to visit several new aspects of the C++ programming language, outlined in Chapters 1 and 2, yet which we originally bypassed. In particular, we will explore:
The definition of Abstract Classes and its relation to class inheritence in defining a formal interface for potential classes. (as per Ch. 2.2.5)
The use of Exceptions in handling unexpected scenarios (as per Ch. 2.4).
The use of Templates in writing more generic code (as per Ch 2.3).
Classes and Memory Allocation, and its relation to a copy constructor and the overloading of the assignment operator (as per Ch. 1.5.3).
Ch. 4.2 of the text gives many code fragments related to the defintion of a Stack and its implementation as an ArrayStack. However, those code fragments do not make a complete, compilable C++ program. Instead, we offer our own version of the same classes, as part of a complete project which can be truly compiled (available files).