Question: #pragma once #include StackInterface.hpp #include Node.hpp #include #include using namespace std; template < class T> class DLinkedStack : public StackInterface { private : Node *headPtr;
#pragma once #include "StackInterface.hpp" #include "Node.hpp" #include#include using namespace std; template<class T> class DLinkedStack : public StackInterface { private: Node *headPtr; // Pointer to first node in the chain; Node *topPtr; // Pointer to (last) node in the chain that contains the stack's top public: DLinkedStack(); DLinkedStack(const DLinkedStack &aStack); // Copy constructor virtual ~ DLinkedStack(); // Destructor Node *getPointerTo(const T &target) const; bool isEmpty() const; bool push(const T &newItem); bool pop(); T peek() const; vector toVector() const; Node *getHeadPTR() const; Node *getTopPTR() const; }; template<class T> DLinkedStack ::DLinkedStack() : headPtr(nullptr), topPtr(nullptr) { } template<class T> DLinkedStack ::DLinkedStack(const DLinkedStack &aStack) { //TODO - Implement the copy constructor } template<class T> DLinkedStack ::~DLinkedStack() { //TODO - Implement the destructor } template<class T> Node *DLinkedStack ::getPointerTo(const T &target) const { //TODO - Return the Node pointer that contains the target(return nullptr if not found) //when there is more than one target exists, return the first target from top. } template<class T> bool DLinkedStack ::isEmpty() const { //TODO - Return True if the list is empty } template<class T> bool DLinkedStack ::push(const T &newItem) { //TODO - Push an item on the Doubly Linked Stack } template<class T> bool DLinkedStack ::pop() { //TODO - Pop an item from the stack - Return true if successful } template<class T> T DLinkedStack ::peek() const { //Assume this never fails. //TODO - return the element stored at the top of the stack (topPtr) } template<class T> vector DLinkedStack ::toVector() const { // DO NOT MODIFY THIS FUNCTION vector returnVector; // Put stack items into a vector in top to bottom order Node *curPtr = topPtr; while (curPtr != nullptr) { returnVector.push_back(curPtr->getItem()); curPtr = curPtr->getPrev(); } return returnVector; } template<class T> Node *DLinkedStack ::getHeadPTR() const { // DO NOT MODIFY THIS FUNCTION return headPtr; } template<class T> Node *DLinkedStack ::getTopPTR() const { // DO NOT MODIFY THIS FUNCTION return topPtr; }
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
