?? testprogstack.cpp
字號:
//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;
return 0;
}
void testCopyConstructor(stackType<int> otherStack)
{
if (!otherStack.isEmptyStack())
cout << "otherStack is not empty." << endl
<< "The top element of otherStack: "
<< otherStack.top() << endl;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -