testprogstack.cpp
来自「C++编成数据结构与程序设计方法 D.S.Malk编著」· C++ 代码 · 共 58 行
CPP
58 行
//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 + =
减小字号Ctrl + -
显示快捷键?