stackType<Type> Using the above UML diagram of the stackType<Type> class, implem
ID: 3818459 • Letter: S
Question
stackType<Type>
Using the above UML diagram of the stackType<Type> class, implement the
copyStack(const stackType <Type> &)
function
stackType<Type>
-maxStackSize: int-StackTop: int
-*list: Type +operator=(const stackType <Type>&): const stackType <type>&
+initializeStack() const: bool
+isEmptyStack() const: bool
+push(const Type&): void
+top() const: Type
+pop() : void
-CopyStack(const stackType<Type>&): void
+stackStype(int = 100)
+stackStype(const stackType<Type>&)
+~stackType
Explanation / Answer
void copyStack(const StackType<Type> &other) //Copies the elements of other stack to this stack.
{
StackTop = other.StackTop; //Assigns the StackTop value.
list = new Type[maxStackSize]; //Creates the required space.
for(int i = 0; i < StackTop; i++) //Copies the stack elements.
list[i] = other.list[i];
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.