Question: Could you please help. Needs to be in C++. - implement the Stack ADT using the array based approach: - implement constructor, copy constructor, assignment
Could you please help. Needs to be in C++.
- implement the Stack ADT using the array based approach:
- implement constructor, copy constructor, assignment operator, destructor;
- push, pop;
- clear, isFull, isEmpty;
Implementations need to be done on the stackArray cpp file included below.
stackArray.h
//-------------------------------------------------------------------- // // Laboratory 6 StackLinked.h // // Class declaration for the linked implementation of the Stack ADT // //--------------------------------------------------------------------
#ifndef STACKARRAY_H #define STACKARRAY_H
#include
using namespace std;
#include "Stack.h"
template
void push(const DataType& newDataItem) throw (logic_error); DataType pop() throw (logic_error);
void clear();
bool isEmpty() const; bool isFull() const;
void showStructure() const;
private: int maxSize; int top; DataType* dataItems; };
#endif //#ifndef STACKARRAY_H
stackArray.cpp #include "StackArray.h"
template
template
template
template
template
template
template
template
template
template
// Array implementation. Outputs the data items in a stack. If the // stack is empty, outputs "Empty stack". This operation is intended // for testing and debugging purposes only.
{ if( isEmpty() ) { cout << "Empty stack." << endl; } else { int j; cout << "Top = " << top << endl; for ( j = 0 ; j < maxSize ; j++ ) cout << j << "\t"; cout << endl; for ( j = 0 ; j <= top ; j++ ) { if( j == top ) { cout << '[' << dataItems[j] << ']'<< "\t"; // Identify top } else { cout << dataItems[j] << "\t"; } } cout << endl; } cout << endl; }
Thank you for your help.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
