当前位置: 首页>>代码示例>>C++>>正文


C++ Stack::HasValue方法代码示例

本文整理汇总了C++中Stack::HasValue方法的典型用法代码示例。如果您正苦于以下问题:C++ Stack::HasValue方法的具体用法?C++ Stack::HasValue怎么用?C++ Stack::HasValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Stack的用法示例。


在下文中一共展示了Stack::HasValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: StackExpansion_Test

void StackExpansion_Test()
{
	ERROR errorCode = NOERR;
	Stack<int> stack = Stack<int>();
	stack.Push(1, &errorCode);
	stack.Push(2, &errorCode);
	stack.Push(3, &errorCode);
	stack.Push(4, &errorCode);
	stack.Push(5, &errorCode);
	stack.Push(6, &errorCode);
	stack.Push(7, &errorCode);
	stack.Push(8, &errorCode);
	if (errorCode != NOERR)
	{
		std::cout << "ERROR -- Got error on one of the pushes. StackExpansion_Test failed!" << std::endl;
	}
	if (!stack.HasValue(&errorCode))
	{
		std::cout << "ERROR -- Data not left in stack after pushes. StackExpansion_Test failed!" << std::endl;
		return;
	}
	if (stack.Pop(&errorCode) != 8 ||
		stack.Pop(&errorCode) != 7 ||
		stack.Pop(&errorCode) != 6 ||
		stack.Pop(&errorCode) != 5 ||
		stack.Pop(&errorCode) != 4 ||
		stack.Pop(&errorCode) != 3 ||
		stack.Pop(&errorCode) != 2 ||
		stack.Pop(&errorCode) != 1)
	{
		std::cout << "ERROR -- Data was not correct in the stack once it was expanded. StackExpansion_Test failed!" << std::endl;
	}
	if (errorCode != NOERR)
	{
		std::cout << "ERROR -- Got error on one of the pops. StackExpansion_Test failed!" << std::endl;
	}
	std::cout << "SUCCESS -- StackExpansion_Test" << std::endl;
}
开发者ID:davidov541,项目名称:DailyProgrammerSolutions,代码行数:38,代码来源:StackTests.cpp

示例2: NoElementStack_Test

void NoElementStack_Test()
{
	ERROR errorCode = NOERR;
	Stack<int> stack = Stack<int>();
	if (stack.HasValue(&errorCode))
	{
		std::cout << "ERROR -- HasValue returned true with no elements. NoElementStack_Test failed!" << std::endl;
	}
	if (errorCode != NOERR)
	{
		std::cout << "ERROR -- HasValue returned an error when called with no elements. NoElementStack_Test failed!" << std::endl;
	}
	stack.Pop(&errorCode);
	if (errorCode != NOELEMENTS)
	{
		std::cout << "ERROR -- Pop did not return correct error when called with no elements. NoElementStack_Test failed!" << std::endl;
	}
	stack.Peek(&errorCode);
	if (errorCode != NOELEMENTS)
	{
		std::cout << "ERROR -- Peek did not return correct error when called with no elements. NoElementStack_Test failed!" << std::endl;
	}
	std::cout << "SUCCESS -- NoElementStack_Test" << std::endl;
}
开发者ID:davidov541,项目名称:DailyProgrammerSolutions,代码行数:24,代码来源:StackTests.cpp

示例3: PushPeek_Test

void PushPeek_Test()
{
	int errorCode = NOERR;
	Stack<int> stack = Stack<int>();
	if (stack.HasValue(&errorCode))
	{
		std::cout << "ERROR -- Data in stack before first push. PushPeek_Test failed!" << std::endl;
		return;
	}
	if (errorCode != NOERR)
	{
		std::cout << "ERROR -- Got error on first call to HasValue. PushPeek_Test failed!" << std::endl;
	}
	stack.Push(1, &errorCode);
	if (errorCode != NOERR)
	{
		std::cout << "ERROR -- Got error on first call to Push. PushPeek_Test failed!" << std::endl;
	}
	if (stack.Peek(&errorCode) != 1)
	{
		std::cout << "ERROR -- Peek did not produce what we pushed on. PushPeek_Test failed!" << std::endl;
		return;
	}
	if (errorCode != NOERR)
	{
		std::cout << "ERROR -- Got error on first call to Peek. PushPeek_Test failed!" << std::endl;
	}
	if (!stack.HasValue(&errorCode))
	{
		std::cout << "ERROR -- No data left after first peek. PushPeek_Test failed!" << std::endl;
		return;
	}
	if (errorCode != NOERR)
	{
		std::cout << "ERROR -- Got error on second call to HasValue. PushPeek_Test failed!" << std::endl;
	}
	stack.Push(2, &errorCode);
	if (errorCode != NOERR)
	{
		std::cout << "ERROR -- Got error on second call to Push. PushPeek_Test failed!" << std::endl;
	}
	if (stack.Peek(&errorCode) != 2)
	{
		std::cout << "ERROR -- Peek did not produce what we pushed on the second time. PushPeek_Test failed!" << std::endl;
		return;
	}
	if (errorCode != NOERR)
	{
		std::cout << "ERROR -- Got error on second call to Peek. PushPeek_Test failed!" << std::endl;
	}
	if (!stack.HasValue(&errorCode))
	{
		std::cout << "ERROR -- No data left after second peek. PushPeek_Test failed!" << std::endl;
		return;
	}
	if (errorCode != NOERR)
	{
		std::cout << "ERROR -- Got error on third call to HasValue. PushPeek_Test failed!" << std::endl;
	}
	std::cout << "SUCCESS -- PushPeek_Test" << std::endl;
}
开发者ID:davidov541,项目名称:DailyProgrammerSolutions,代码行数:61,代码来源:StackTests.cpp


注:本文中的Stack::HasValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。