Question
- implement the Stack ADT using the linked list approach Attached is the StackLinked.cpp and StackLinked.h **USE C++ PROGRAMMING LANGUAGE. StackLinked.cpp #include StackLinked.h template StackLinked
- implement the Stack ADT using the linked list approach
Attached is the StackLinked.cpp and StackLinked.h **USE C++ PROGRAMMING LANGUAGE.
StackLinked.cpp
#include "StackLinked.h"
template
StackLinked
{
}
template
StackLinked
{
}
template
StackLinked
{
}
template
StackLinked
{
clear();
}
template
void StackLinked
{
}
template
DataType StackLinked
{
DataType t = 0;
return t;
}
template
void StackLinked
{
}
template
bool StackLinked
{
return false;
}
template
bool StackLinked
{
return false;
}
template
void StackLinked
{
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;
}
}
------------
StackLinked.h
#ifndef STACKARRAY_H
#define STACKARRAY_H
#include
#include
using namespace std;
#include "Stack.h"
template
class StackLinked : public Stack
public:
StackLinked(int maxNumber = Stack
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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started