Example #1
0
	T pop()
	{//出队
		if (B.empty())
		{//若B空,则队首元素应该在A的栈底
			while (!A.empty())//将A中元素全部压入B
				B.push(A.pop());
		}
		return B.pop();//出B栈
	}
	int max()
	{
		if (empty()) return 0;
		if (head.empty()) 
			return tail.max();
		if (tail.empty()) 
			return head.max();
		else
			return std::max(tail.max(),head.max());
	}
	void pop()
	{
		if (head.empty())
		{
			while (!tail.empty())
			{
				head.push(tail.top());
				tail.pop();
			}
		}
		head.pop();
	}
Example #4
0
	bool empty()const { return A.empty() && B.empty(); }
	bool empty ()
	{
		return head.empty() && tail.empty();
	}