I\'m trying to write the following using C++ regarding stacks but I\'m stuck: __
ID: 3648459 • Letter: I
Question
I'm trying to write the following using C++ regarding stacks but I'm stuck: __________________________________________________________________
Write a member function of class StackType that updates the stack when a page is referenced.
Assume a stack that can hold 5 values, and the next page referenced is 7,
then the function searches the stack for the page reference 7;
if it finds it, it removes it from the stack and places it at the top;
if there is not a 7 in the list, the last page reference in the stack is removed and the 7 is placed at the top of the stack.
for example:
stack:
9
5
6
7
1
after referencing 7:
7
9
5
6
1
use a non-recursive solution (can use a helper stack)
Use the following header:
template <class Type>
void stackType<Type>::update(Type t); __________________________________________________________________
Please read what I asked thoroughly before answering.
Explanation / Answer
template void stackType::initializeStack() { stackTop = 0; } template void stackType::destroyStack() { stackTop = 0; } template bool stackType::isEmptyStack() { return(stackTop == maxStackSize); } template bool stackType::isFullStack() { return(stackTop == maxStackSize); } template void stackType::push(const Type& newItem) { if(!isFullStack()) { list[stackTop] = newItem; stackTop++; } else cerrRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.