Question: LAB 6 (Stack ADT) Exercises: At Class 40 pts (deadline: 12:40 pm 2/10/2021): implement the Stack ADT using the array based approach: - implement constructor,
LAB 6 (Stack ADT)
Exercises: At Class 40 pts (deadline: 12:40 pm 2/10/2021):
implement the Stack ADT using the array based approach:
- implement constructor, copy constructor, assignment operator, destructor; (20 pts)
push, pop; (15 pts)
- clear, isFull, isEmpty; (5 pts)
#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; }
//-------------------------------------------------------------------- // // 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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
