Question: bool push (const ItemType& newItem) ; bool pop () ; **@throw PrecondViolatedExcept the stack is empty */ ItemType peek () const throw (PrecondViolatedExcept ; ):

 bool push (const ItemType& newItem) ; bool pop () ; **@throwPrecondViolatedExcept the stack is empty */ ItemType peek () const throw (PrecondViolatedExcept; ): / / end LinkedStack where the class DLNode is definedas template class DLNode private: ItemType item; DLNode* previous; / / pointerto previous node DLNode* next; / / pointer to next node public:/ / Constructors DLNode () ; DLNode (const ItemType& anItem) ; DLNode(const ItemType& anItem, DLNode* previousNodePtr, DLNode* nextNodePtr) ;In Project4, you used a

bool push (const ItemType& newItem) ; bool pop () ; **@throw PrecondViolatedExcept the stack is empty */ ItemType peek () const throw (PrecondViolatedExcept ; ): / / end LinkedStack where the class DLNode is defined as template class DLNode private: ItemType item; DLNode* previous; / / pointer to previous node DLNode* next; / / pointer to next node public: / / Constructors DLNode () ; DLNode (const ItemType& anItem) ; DLNode (const ItemType& anItem, DLNode* previousNodePtr, DLNode* nextNodePtr) ;In Project4, you used a doubly linked list to implement ADT Bag Consider using linked list to implement ADT Stack as below. template class DLinkedStack : public StackInterface private: DLNode * topPtr; / / Pointer to first node in the chain; / / this node contains the stack's top public: / / Constructors and destructor: DLinkedStack () ; DLinkedStack (const DLinkedStack& aStack) ; virtual ~DLinkedStack () ; / / Stack operations : bool isEmpty () const; bool push (const ItemTypes newItem) ; bool pop ( ) ; /** @throw PrecondViolatedExceptin the stack is empty * /owing answers is the correct implementation for the member function push in the class DLinkedStack defined in this section? al template bool DLinkedStack ::push( const Item Type& newEntry) if( topPur-NULL) DNode* newNodePtr = new DLNode* newNodePtr = new DLNode(newEntry). newNodePtr->setNext(topPtr); topPtr->setPrevious(newNodePtr); 10 topPtr = newNodePtr; V new NodePtr = NULL: return true; } // end pushwhere the class DLNode is defined as templatecclass Itemtype> class DLNode private: ItemType item; DLNode* previous; / / pointer to previous node DLNode > next; / / pointer to next node public: / / Constructors DLNode () ; DLNode (const ItemType& anItem) ; DLNode (const ItemType& anItem, DLNode > previousllodeptr. DLNode* nextNodePtr) ; void setItem (const ItemType& anItem) ; void setPrevious (DLNode* previousModePtr) : void setNext (DLNode* nextNodePtr) ; ItemType getItem () const ; DLNode* getPrevious () const; DLNode* getNext () const;O d template bool DLinkedStack::push(const Item Type& newEntry) if( topPtr=NULL) DNode* newNodePtr = new DLNode(newEntry): topPtr = newNodePtr; else DNode* newNodePtr = new DLNode(newEntry): newNodePtr->setNext(topPtr); topPtr = newNodePtr; new NodePtr = NULL; return true; } // end push\f\f

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 Programming Questions!