testproglinkedstack.cpp

来自「上载的是c++源代码」· C++ 代码 · 共 58 行

CPP
58
字号
//This program tests various operations of a linked stack

#include <iostream>
#include "linkedStack.h"

using namespace std;

void testCopy(linkedStackType<int> OStack);

int main()
{
	linkedStackType<int> stack;
	linkedStackType<int> otherStack;
	linkedStackType<int> newStack;

	stack.push(34);
	stack.push(43);
	stack.push(27);
	newStack = stack;

	cout << "After the assignment operator, newStack: " 
		  << endl; 

	while (!newStack.isEmptyStack())
	{
		cout << newStack.top() << endl;	
		newStack.pop();
	}

	otherStack = stack;

	cout << "Testing the copy constructor." << endl;

	testCopy(otherStack);

	cout << "After the copy constructor, otherStack: " << endl;

	while (!otherStack.isEmptyStack())
	{
		cout << otherStack.top() << endl;	
		otherStack.pop();
	}

	return 0;
}
 
     //function to test the copy constructor
void testCopy(linkedStackType<int> OStack) 
{
	cout << "Stack in the function testCopy:" << endl;

	while (!OStack.isEmptyStack())
	{
		cout << OStack.top() << endl;	
		OStack.pop();
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?