//************************************************************* // Author: D.S. Malik // // This program tests various operations of a stack. //************************************************************* #include #include "myStack.h" using namespace std; void testCopyConstructor(stackType otherStack); int main() { stackType stack(50); stackType copyStack(50); stackType dummyStack(100); stack.initializeStack(); stack.push(23); stack.push(45); stack.push(38); copyStack = stack; //copy stack into copyStack cout << "The elements of copyStack: "; while (!copyStack.isEmptyStack()) //print copyStack { cout << copyStack.top() << " "; copyStack.pop(); } cout << endl; copyStack = stack; testCopyConstructor(stack); //test the copy constructor if (!stack.isEmptyStack()) cout << "The original stack is not empty." << endl << "The top element of the original stack: " << copyStack.top() << endl; dummyStack = stack; //copy stack into dummyStack cout << "The elements of dummyStack: "; while (!dummyStack.isEmptyStack()) //print dummyStack { cout << dummyStack.top() << " "; dummyStack.pop(); } cout << endl; return 0; } void testCopyConstructor(stackType otherStack) { if (!otherStack.isEmptyStack()) cout << "otherStack is not empty." << endl << "The top element of otherStack: " << otherStack.top() << endl; }