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


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

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


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

示例1: main

int main (int argv, char **argc) {

	MaxStack maxStackObj;
	try {
		maxStackObj.Pop();
	} catch (std::exception &e) {
		std::cout << e.what() << std::endl;
	}
	try {
		maxStackObj.Max();
	} catch (std::exception &e) {
		std::cout << e.what() << std::endl;
	}
	maxStackObj.Push(-78);
	std::cout << "Max: " << maxStackObj.Max() << std::endl;
	maxStackObj.Push(-7);
	std::cout << "Max: " << maxStackObj.Max() << std::endl;
	maxStackObj.Push(3);
	std::cout << "Max: " << maxStackObj.Max() << std::endl;
	maxStackObj.Pop();
	std::cout << "Max: " << maxStackObj.Max() << std::endl;
	maxStackObj.Pop();
	std::cout << "Max: " << maxStackObj.Max() << std::endl;
	maxStackObj.Pop();
	maxStackObj.Push(0);
	std::cout << "Max: " << maxStackObj.Max() << std::endl;
	maxStackObj.Push(100);
	std::cout << "Max: " << maxStackObj.Max() << std::endl;

	Stack stackObj;
	std::cout << "Result of RPN expr: (3 4 + 2 * 1 +) is :"
			<< stackObj.EvaluateRpn("3 4 + 2 * 1 +") << std::endl;

	std::cout << "Result of RPN expr: (5 1 2 + 4 * + 3 -) is :"
			<< stackObj.EvaluateRpn("5 1 2 + 4 * + 3 -") << std::endl;

	std::cout << "Expression : [({[()]})] is :";
	stackObj.IsWellFormed("[({[()]})]") ?
			std::cout << "Well Formed" << std::endl :
			std::cout << "Not Well Formed" << std::endl;

	std::cout << "Expression : [{{{}}}[][]]]]({[()]})] is :";
	stackObj.IsWellFormed("[{{{}}}[][]]]]({[()]})]") ?
			std::cout << "Well Formed" << std::endl :
			std::cout << "Not Well Formed" << std::endl;

	std::cout << "Expression : ({[()]}){{}}[ is :";
	stackObj.IsWellFormed("({[()]}){{}}[") ?
			std::cout << "Well Formed" << std::endl :
			std::cout << "Not Well Formed" << std::endl;


	Node node(23);
	Node node1(37);
	Node node2(29);
	Node node3(41);
	Node node4(31);

	node.right = &node1;
	node1.left = &node2;
	node1.right = &node3;
	node2.right = &node4;

	std::cout << "BST InOrder with stack from 23 is: " << std::endl;
	std::vector<int> inOrder = stackObj.BSTSortedOrderWithStack(&node);
	for (auto i : inOrder) {
		std::cout << i << " ";
	}
	std::cout << std::endl;

	std::cout << "Building with input stream East to West: [4 3 5 3 1 4 2] " << std::endl;
	std::cout << "Building indices with sunset views are: " << std::endl;
	std::vector<int> result1 = stackObj.BuildingsWithSunsetViewEastToWest("4 3 5 3 1 4 2");
	for (auto i : result1) {
		std::cout << i+1 << " ";
	}
	std::cout << std::endl;

	std::cout << "Building with input stream West to East: [2 4 1 3 5 3 4] " << std::endl;
	std::cout << "Building indices with sunset views are: " << std::endl;
	std::vector<int> result2 = stackObj.BuildingsWithSunsetViewWestToEast("2 4 1 3 5 3 4");
	for (auto i : result2) {
		std::cout << i+1 << " ";
	}
	std::cout << std::endl;

	std::stack<int> s;
	s.push(5);
	s.push(4);
	s.push(3);
	s.push(2);
	s.push(1);
	std::cout << "Stack with LIFO: 1 2 3 4 5" << std::endl;
	stackObj.SortStack(s);
	std::cout << "Sorted Stack in descending order" << std::endl;
	int size = s.size();
	for (int i = 0; i < size; i++) {
		std::cout << s.top() << " ";
		s.pop();
	}
//.........这里部分代码省略.........
开发者ID:palwe-prafulla,项目名称:coding-practice,代码行数:101,代码来源:test-stack.cpp


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