Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

At home 60 pts (deadline: 11:00 am 2/10/2021): - implement the Stack ADT using the linked list approach: - implement constructor, copy constructor, assignment operator,

At home 60 pts (deadline: 11:00 am 2/10/2021):

- implement the Stack ADT using the linked list approach:

- implement constructor, copy constructor, assignment operator, destructor; (25 pts) -

push, pop; (25 pts) -

clear , isFull, isEmpty; (10 pts)

//-------------------------------------------------------------------- // // Laboratory 6 StackArray.h // // Class declaration for the array implementation of the Stack ADT // //--------------------------------------------------------------------

#ifndef STACKARRAY_H #define STACKARRAY_H

#include #include

using namespace std;

#include "Stack.h"

template class StackLinked : public Stack {

public:

StackLinked(int maxNumber = Stack::MAX_STACK_SIZE); StackLinked(const StackLinked& other); StackLinked& operator=(const StackLinked& other); ~StackLinked();

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:

class StackNode { public: StackNode(const DataType& nodeData, StackNode* nextPtr) { dataItem = nodeData; next = nextPtr; }

DataType dataItem; StackNode* next; };

StackNode* top; };

#endif //#ifndef STACKARRAY_H

#include "StackLinked.h"

template StackLinked::StackNode::StackNode(const DataType& newDataItem, StackLinked::StackNode* nextPtr)

// Creates a stack node containing item newDataItem and next pointer // nextPtr.

: dataItem(newDataItem), next(nextPtr) { }

template StackLinked::StackLinked (int maxNumber) // Creates an empty stack. The parameter maxNumber is provided for // compatability with the array implementation and is ignored. { }

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

template StackLinked& StackLinked::operator=(const StackLinked& other) // Overloaded assignment operator for the StackLinked class. // Because this function returns a StackLinked object reference, // it allows chained assignment (e.g., stack1 = stack2 = stack3).

{ }

template StackLinked::~StackLinked() // Destructor. Frees the memory used by a stack. { clear(); }

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

template DataType StackLinked::pop() throw (logic_error) // Removes the topmost item from a stack and returns it. { }

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

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

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

template void StackLinked::showStructure() const { if( isEmpty() ) { cout << "Empty stack" << endl; } else { cout << "Top\t"; for (StackNode* temp = top; temp != 0; temp = temp->next) { if( temp == top ) { cout << "[" << temp->dataItem << "]\t"; } else { cout << temp->dataItem << "\t"; } } cout << "Bottom" << endl; }

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Medical Image Databases

Authors: Stephen T.C. Wong

1st Edition

1461375398, 978-1461375395

More Books

Students also viewed these Databases questions

Question

3. How effective is the team?

Answered: 1 week ago

Question

=+How should it be delivered?

Answered: 1 week ago

Question

=+4 How does one acquire a global mindset?

Answered: 1 week ago