#include #include "myStack.h" using namespace std; template void ReplaceStackItem(stackType &astack, T olditem, T newitem); int main() { stackType astack; astack.push(5); astack.push(6); ReplaceStackItem(&astack, 1, 2); while(!astack.isEmptyStack()) { cout << astack.top(); astack.pop(); } return 0; } template void ReplaceStackItem(stackType &astack, T olditem, T newitem) { stackType backup = astack; stackType rstack; while(!astack.isEmptyStack()) { if(astack.top() == olditem) { astack.pop(); astack.push(newitem); } backup.push(astack.top()); } while(!backup.isEmptyStack()) { astack.push(backup.top()); backup.pop(); } }