// Author: D.S. Malik // // This program tests various operations of a linked stack. //************************************************************* #include #include "linkedStack.h" using namespace std; void testCopy(linkedStackType OStack); int main() { linkedStackType stack; linkedStackType otherStack; linkedStackType newStack; //Add elements into stack stack.push(34); stack.push(43); stack.push(27); //Use the assignment operator to copy the elements //of stack into newStack newStack = stack; cout << "After the assignment operator, newStack: " << endl; //Output the elements of newStack while (!newStack.isEmptyStack()) { cout << newStack.top() << endl; newStack.pop(); } //Use the assignment operator to copy the elements //of stack into otherStack otherStack = stack; cout << "Testing the copy constructor." << endl; testCopy(otherStack); cout << "After the copy constructor, otherStack: " << endl; while (!otherStack.isEmptyStack()) { cout << otherStack.top() << endl; otherStack.pop(); } return 0; } //Function to test the copy constructor void testCopy(linkedStackType OStack) { cout << "Stack in the function testCopy:" << endl; while (!OStack.isEmptyStack()) { cout << OStack.top() << endl; OStack.pop(); } }