I refer to Nak Gui Choi's solution.I change Copy Constructor and Reverse () function that use depth() function.
<Copy Constructor>Stack::Stack(const Stack& S){
Node* temp = S._top;
unsigned int d= depth();
for(;d>0&&temp != 0;d--){
push(temp->_data);
temp = temp->_next;
}
reverse();
}
< Reverse () >void Stack::reverse(){
Node* temp = _top;
_top = (Node*)0;
unsigned int d= depth();
for(;d>0&&temp!=0;d--){
push(temp->_data);
temp = temp->_next;
}
< Depth() >unsigned int Stack::depth(){
unsigned int dept = 0;
Node* temp = this->_top;
for(;temp !=0;dept++){
temp = temp->_next;
} return dept;
}