Esempio n. 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();
	}
Esempio n. 4
0
	void print()const
	{
		A.print();
		B.print();
	}
Esempio n. 5
0
	void push(const T & val) { A.push(val); }
Esempio n. 6
0
	T max()const { return maxOfTwo(A.max(), B.max()); }
Esempio n. 7
0
	bool empty()const { return A.empty() && B.empty(); }
	bool empty ()
	{
		return head.empty() && tail.empty();
	}
	void push(const int& x)
	{
		tail.push(x);
	}