Access over 35 million academic & study documents

Solution

Content type
User Generated
Subject
Computer Science
Type
Homework
Rating
Showing Page:
1/6
stackADT.h
template <class Type>
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.
//Precondition: The stack exists and is not full.
//Postcondition: The stack is changed and newItem is added
//to the top of the stack.
virtual Type top() const = 0;
//Function to return the top element of the stack.
//Precondition: The stack exists and is not empty.
//Postcondition: If the stack is empty, the program
//terminates; otherwise, the top element of the stack
//is returned.
virtual void pop() = 0;
//Function to remove the top element of the stack.
//Precondition: The stack exists and is not empty.
//Postcondition: The stack is changed and the top element
//
//is removed from the stack.
};
myStack.h
//Header file: myStack.h
#ifndef H_StackType
#define H_StackType
#include <iostream>
#include <cassert>
#include "stackADT.h"
using namespace std;
//Place the definition of the class template stackType, as given
//previously in this chapter, here.
//Place the definitions of the member functions as discussed here.
template <class Type>
class stackType : public stackADT<Type>
{
public:

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/6
const stackType<Type>& operator=(const stackType<Type>&);
//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.400 | Chapter 7: Stacks
bool isFullStack() const;
//Function to determine whether the stack is full.
//Postcondition: Returns true if the stack is full,
//otherwise returns false.
void push(const Type& newItem);
//Function to add newItem to the stack.
//Precondition: The stack exists and is not full.
//Postcondition: The stack is changed and newItem is
//added to the top of the stack.
Type top() const;
//Function to return the top element of the stack.
//Precondition: The stack exists and is not empty.
//Postcondition: If the stack is empty, the program
//terminates; otherwise, the top element of the stack
//is returned.
void pop();
//Function to remove the top element of the stack.
//Precondition: The stack exists and is not empty.
//Postcondition: The stack is changed and the top element is
//removed from the stack.
stackType(int stackSize = 100);
//Constructor
//Create an array of the size stackSize to hold
//the stack elements. The default stack size is 100.
//Postcondition: The variable list contains the base address
// of the array, stackTop = 0, and maxStackSize = stackSize
stackType(const stackType<Type>& otherStack);
//Copy constructor
~stackType();
//Destructor
//Remove all the elements from the stack.
//Postcondition: The array (list) holding the stack
//elements is deleted.
private:
int maxStackSize; //variable to store the maximum stack size
int stackTop;
//variable to point to the top of the stack
Type *list; //pointer to the array that holds the stack elements
void copyStack(const stackType<Type>& otherStack);
//Function to make a copy of otherStack.
//Postcondition: A copy of otherStack is created and assigned
//to this stack.
};

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/6

Sign up to view the full document!

lock_open Sign Up
End of Preview - Want to read all 6 pages?
Access Now
Unformatted Attachment Preview
stackADT.h 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. //Precondition: The stack exists and is not full. //Postcondition: The stack is changed and newItem is added //to the top of the stack. virtual Type top() const = 0; //Function to return the top element of the //Precondition: The stack exists and is not //Postcondition: If the stack is empty, the //terminates; otherwise, the top element of //is returned. stack. empty. program the stack virtual void pop() = 0; //Function to remove the top element of the stack. //Precondition: The stack exists and is not empty. //Postcondition: The stack is changed and the top element // //is removed from the stack. }; myStack.h //Header file: myStack.h #ifndef H_StackType #define H_StackType #include #include #include "stackADT.h" using namespace std; //Place the definition of the class template stackType, as given //previously in this chapter, here. //Place the definitions of t ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Anonymous
Very useful material for studying!

Studypool
4.7
Indeed
4.5
Sitejabber
4.4

Similar Documents