⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testprogstack.cpp

📁 上载的是c++源代码
💻 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 + -