All pastes #52551 Raw Edit

Unnamed

public cpp v1 · immutable
#52551 ·published 2006-05-01 13:06 UTC
rendered paste body
#include <iostream>#include "myStack.h"using namespace std;template<class T>void ReplaceStackItem(stackType<T> &astack, T olditem, T newitem);int main(){	stackType<int> astack;	astack.push(5);	astack.push(6);	ReplaceStackItem(&astack, 1, 2);	while(!astack.isEmptyStack())	{		cout << astack.top();		astack.pop();	}	return 0;}template<class T>void ReplaceStackItem(stackType<T> &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();	}}