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 StackArray::StackArray(int maxNumber) // Creates an empty stack. {

}

template StackArray::StackArray(const StackArray& other) // Copy constructor for linked stack { }

template StackArray& StackArray::operator=(const StackArray& other) { }

template StackArray::~StackArray() // Frees the memory used by a stack. { }

template void StackArray::push(const DataType& newDataItem) throw (logic_error) // Inserts newDataItem onto the top of a stack. { }

template DataType StackArray::pop() throw (logic_error) // Removes the topmost data item from a stack and returns it. { DataType t; return t; }

template void StackArray::clear() // Removes all the data items from a stack. { }

template bool StackArray::isEmpty() const // Returns true if a stack is empty. Otherwise, returns false. { return false; }

template bool StackArray::isFull() const // Returns true if a stack is full. Otherwise, returns false. { return false; }

template void StackArray::showStructure() const

// 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 #include

using namespace std;

#include "Stack.h"

template class StackArray : public Stack { public: StackArray(int maxNumber = Stack::MAX_STACK_SIZE); StackArray(const StackArray& other); StackArray& operator=(const StackArray& other); ~StackArray();

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!