/* * File: stacktest.cpp * Author: Joni Alon * Topic: Templates * ----------------------------------------------------- * * OVERVIEW: * ========= * This program tests stacks of integers and characters. * */ #include #include "stack2.h" int main() { int size; cout << "Enter the size of the int Stack (greater than 0): "; cin >> size; // stack of integers { Stack stack(size); // A stack to hold integers. cout << "\nEnter integers you wish to push onto the Stack.\n"; cout << "Enter -1 to finish.\n"; int a; cin >> a; while (a != -1) { stack.push(a); cin >> a; } /* * Pop each of the integers off of * the stack and print them out. */ cout << "\nPopped integers are:" << endl; while (!stack.isEmpty()) { a = stack.pop(); cout << a << endl; } } // stack of characters { Stack stack(size); // A stack to hold characters. cout << "\nEnter characters you wish to push onto the Stack.\n"; cout << "Enter Z to finish.\n"; char ch; cin >> ch; while (ch != 'Z') { stack.push(ch); cin >> ch; } /* * Pop each of the characters off of * the stack and print them out. */ cout << "\nPopped characters are:" << endl; while (!stack.isEmpty()) { ch = stack.pop(); cout << ch << endl; } } return 0; }