Question
Two stacks of the same type are the same if they have the same number of elements and their elements at the corresponding positions are
Two stacks of the same type are the same if they have the same number of elements and their elements at the corresponding positions are the same.
Overload the relational operator == for the class stackType that returns true if two stacks of the same type are the same; it returns false otherwise.
Also, write the definition of the function template to overload this operator.
Write a program to test the various overloaded operators and functions of class stackType.
task:
Two stacks of the same type are the same if they have the same number of elements and their elements at the corresponding positions are the same.
Overload the relational operator == for the class stackType that returns true if two stacks of the same type are the same; it returns false otherwise.
Also, write the definition of the function template to overload this operator.
Write a program to test the various overloaded operators and functions of class stackType.
main.cpp:
stackTop = 0;
} // end function initializeStack
// check for stack fullness
template
bool stackType
{
return ( stackTop == maxStackSize );
} // end function isFullStack
// check for stack empty
template
bool stackType
{
return ( stackTop == 0 );
} // end function isEmptyStack
// insert an element into stack
template
void stackType
{
if ( !isFullStack() )
{
myStack.h:
#ifndef H_StackType
#define H_StackType
#include
#include
#include "stackADT.h"
using namespace std;
template
class stackType: public stackADT
{
public:
const stackType
//Overload the assignment operator.
void initializeStack();
//Function to initialize the stack to an empty state.
//Postcondition: stackTop = 0
bool isEmptyStack() const;
//Function to determine whether the stack is empty.
//Postcondition: Returns true if the stack is empty,
// otherwise returns false.
bool isFullStack() const;
//Function to determine whether the stack is full.
stackATD.h:
#ifndef H_StackADT
#define H_StackADT
template
class stackADT
{
public:
virtual void initializeStack() = 0;
//Method to initialize the stack to an empty state.
//Postcondition: Stack is empty
virtual bool isEmptyStack() const = 0;
//Function to determine whether the stack is empty.
//Postcondition: Returns true if the stack is empty,
// otherwise returns false.
virtual bool isFullStack() const = 0;
//Function to determine whether the stack is full.
//Postcondition: Returns true if the stack is full,
// otherwise returns false.
virtual void push(const Type& newItem) = 0;
//Function to add newItem to the stack.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started