A stack is used for pressing elements such
Another stack pop-up element. If an empty stack is encountered in a pop-up operation, the elements in the stack are transmitted to the stack one by one.
# Include "stdafx. H"
# Include <stack>
Template <class T, Class C = STD: vector <t>
Class queue ...{
Public:
Typedef typename C: vaule_type;
Typedef typename C: size_type;
Typedef typename C conainer_type;
Explicit Queue (C const & contents = C ())
: Outstack _ (contents )...{}
Bool empty () const
... {Return instack _. Empty () & outstack _. Empty ();}
Size_type size () const
... {Return instack _. Size () + outstack _. Size ();}
Vaule_type & Front ()
... {Transfer (); Return outstack _. Top ();}
Vaule_type const & Front ()
... {Transfer (); Return outstack _. Top ();}
Vaule_type & back ()
... {Untransfer (); Return instack _. Top ();}
Vaule_type const & back () const
... {Untransfer (); Return instack _. Top ();}
Void push (vaule_type const & X)... {instack _. Push (x );}
Void POP ()... {transfer (); outstack _. Pop ();}
PRIVATE:
Void transfer ()...{
If (outstack _. Empty ())
While (! Instack _. Empty ())...{
Outstack _. Push (instack _. Top ());
Instack _. Pop ();
}
}
Void untransfer ()...{
Assert (cerr <"Warning: queue: unteansfer () 'ed .");
If (instack _. Empty ())
While (! Outstack _. Empty ())...{
Instack _. Push (outstack_top ());
Outstack _. Pop ();
}
}
STD: Stack <T, C> instack _, outstack _;
T * outbottom _;
};
Int main (INT argc, char * argv [])
...{
Return 0;
}