题目:Use the Stack mehod and a temporary Stack to retrieve entries from the Stack source and add
each entry to the Stack dest and restore the Stack source.
理解:用stack的方法,通过使用临时的stack,从stack source中抽取元素并将每个元素加到stack desk中,并恢复stack source .
代码
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;
}