DDD 2 Qwsss 4 R 5 TRFG
DDD 2 Qwsss 4 R 5 TRFG
template<class ItemType>
StackType<ItemType>::StackType(int max)
{
maxStack = max;
top = -1;
items = new ItemType[max];
}
template<class ItemType>
StackType<ItemType>::~StackType()
{
delete [ ] items;
}
Example: postfix expressions
while (!Stack.IsEmpty()) {
Stack.Pop(item);
3 1
if (item==oldItem) 2 5
tempStack.Push(newItem);
else 1 3
tempStack.Push(item); Stack
}
while (!tempStack.IsEmpty()) {
tempStack.Pop(item);
Stack.Push(item);
} 3
}
oldItem = 2 5
newItem = 5 1