http://zhedahht.blog.163.com/blog/static/2541117420073293950662/
#include <stack> #include <cassert> using namespace std; template <typename T> class CQueue { public: CQueue() {} ~CQueue() {} void append_tail(const T& element); void delete_head(); private: stack<T> m_stack1; stack<T> m_stack2; }; template <typename T> void CQueue<T>::append_tail(const T& element) { m_stack1.push(element); } template <typename T> void CQueue<T>::delete_head() { if (m_stack2.size() <= 0) { while (m_stack1.size()) { m_stack2.push(m_stack1.top()); m_stack1.pop(); } } assert(m_stack2.size() > 0); m_stack2.pop(); } int main() { CQueue<int> q; q.append_tail(10); q.delete_head(); return 0; }