


















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An overview of stacks as a data structure, including definitions, operations, and implementations using C++. stack specifications, push and pop functions, stack overflow and underflow, and implementing stacks using templates and dynamic array allocation. Additionally, it discusses the use of stacks in processing postfix expressions.
Typology: Exams
1 / 26
This page cannot be seen from the preview
Don't miss anything!



















What is a stack?
Push (ItemType newItem)
Pop (ItemType& item)
Stack Implementation #include "ItemType.h" // Must be provided by the user of the class // Contains definitions for MAX_ITEMS and ItemType class StackType { public: StackType(); void MakeEmpty(); bool IsEmpty() const; bool IsFull() const; void Push(ItemType); void Pop(ItemType&); private: int top; ItemType items[MAX_ITEMS]; };
Stack Implementation (cont.) StackType:: StackType() { top = -1; } void StackType:: MakeEmpty() { top = -1; } bool StackType:: IsEmpty() const { return (top == -1); }
Stack overflow
Stack underflow
Implementing stacks using templates
Example using templates
The compiler generates distinct class types and gives its own internal name to each of the types.
Function templates
template
Function templates (cont.) template
Comments using templates
Implementing stacks using dynamic array allocation (cont.) template
Example: postfix expressions