The answer of data structures and program design in C++,Exercises2.2 E2
Error_code copy_stack(Stack &dest, Stack &source);
/*Pre: None.
Post: Stack dest has become an exact copy of Stack source; source is unchanged. if an error is detected, an appropriate code is returned; otherwise,a code o
f success is returned. */
{
Error_code detected = success;
stack temp;
stack entry_item;
while(detected==success&&!source.empty())
{
detected = source.top(item);
detected = source.pop();
if(detected==success)detected = temp.push(item);
}
while (detected==success&&!temp.empty())
{
detected = temp.top(itemp);
detected = temp.pop();
if (detected==success)
detected = source.push(item);
if (detected==success)
detected=dest.push(item);
}
return detected;
}