编写后的函数如下:
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(item);
detected = temp.pop( );
if (detected == success) detected = source.push(item);
if (detected == success) detected = dest.push(item);}
Error_code copy_stack(Stack dest, Stack source)
{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(item);
detected = temp.pop( );
if (detected == success) detected = source.push(item);
if (detected == success) detected = dest.push(item);}
return detected;}