Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Files originally from the book files, I have modified it for the assignment
- //Program to test the various operations of a stack
- #include <iostream>
- #include "myStack.h"
- using namespace std;
- void testCopyConstructor(stackType<int> otherStack);
- int main()
- {
- stackType<int> stack(50);
- stackType<int> copyStack(50);
- stackType<int> 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;
- //start of my code *************************************
- cout << endl << "--START OF MY CODE--" << endl;
- stackType<int> stackOne(20);
- stackType<int> stackTwo(20);
- stackType<int> stackThree(30);
- stackOne.push(4);
- stackOne.push(20);
- stackOne.push(80);
- stackOne.push(100);
- stackOne.push(42);
- stackTwo.push(4);
- stackTwo.push(20);
- stackTwo.push(80);
- stackTwo.push(100);
- stackTwo.push(42);
- stackThree.push(75);
- stackThree.push(60);
- cout << stackOne.top() << " " << stackTwo.top() << endl;
- if(stackOne == stackTwo)
- { cout << "stackOne is equal to stackTwo" << endl;}
- else
- { cout << "stackOne is NOT equal to stackTwo" << endl;}
- if (stackOne == stackThree)
- { cout << "stackOne is equal to stackThree" << endl;}
- else
- { cout << "stackOne is NOT equal to stackThree" << endl;}
- cout << "20 has been pushed onto stackOne" << endl;
- stackOne.push(20);
- if(stackOne == stackTwo)
- { cout << "stackOne is equal to stackTwo" << endl;}
- else
- { cout << "stackOne is NOT equal to stackTwo" << endl;}
- cout << endl << "--END OF MY CODE--" << endl;
- //end of my code ***************************************
- return 0;
- }
- void testCopyConstructor(stackType<int> otherStack)
- {
- if (!otherStack.isEmptyStack())
- cout << "otherStack is not empty." << endl
- << "The top element of otherStack: "
- << otherStack.top() << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment