Question: Class LinkedStack The next class you will be implementing is the linked-list based stack itself, it is similar to the implementation we described in

Class LinkedStackThe next class you will be implementing is the linked-list based stack itself, it is similar to theimpleme TileNode.h1#ifndef _NODE#define _NODE2.3#include Tile.hinNode classThis is a node for a linked list.456789100LinkedStack.h x1 #ifndef _LINKED_STACK2. #define _LINKED_STACK34 #include Stackadt.h5 #include Tile.h6 #includeIStackADT.hx1 Wifndef _STACK_ADT2 #define _STACK_ADT3 #include Tile.h4./*5 StackADT678 class stackADT{ //An exam

Class LinkedStack The next class you will be implementing is the linked-list based stack itself, it is similar to the implementation we described in class. This class is implementing the interface provided called StackADT. The elements in our linked list are pointers to Tile objects. To maintain the stack, each push will insert a new node containing the element at the start/beginning of the linked list (the head of the linked list, at top), and each pop operation will remove the node at the head of the linked list, returning its data. The LinkedStack has two private attributes: TileNode* top - A pointer to the head of the linked list, the top of the stack. int count The number of elements in the stack. You are not to modify the code of LinkedStack.h. For the LinkedStack class, you must implement all the following public methods: 1. LinkedStack::LinkedStack(): A default constructor, here you will initialize the head node called top to null and the number of elements, count, is set to zero. 2. LinkedStack::~LinkedStack(): The deconstructor for the linked list, which is responsible for de-allocating for memory dynamically allocated using the new keyword. Create a pointer variable (TileNode*) that is assigned top, then traverse the linked list, from top to the end of the linked list, deleting each successive node using the delete keyword. You are not responsible for deleting the Tile pointed to by the data attribute, it will be assumed that upon removing data from the stack, those elements will be deleted by the user. 3. void LinkedStack::push (Tile* elem): Create a new TileNode whose data is a Tile* named elem (the input) and insert this node at the head of the linked list (i.e. the beginning of the linked list). Make sure to update the number of elements in the stack appropriately, and when you update the linked list that the insertion is performed correctly. 4. Tile* LinkedStack::pop(): Remove and return element at the top of the stack. As this is a linked list, this means performing a removal of a node at the head of the linked list. If the stack is empty, return null. Make sure to update the number of elements in the stack, and to delete the node (, only the node itself, not any of the data its contents are pointing to,) removed from the linked list (, and the linked list is correctly updated). 5. Tile* LinkedStack::peek (): Return the element at the top of the stack. Do not remove this element (or its node) from the linked list. If the stack is empty, return null. 6. int LinkedStack::size(): Return the size of the stack, the number of elements it contains. 7. bool LinkedStack::isEmpty(): Are there any elements in our stack? False if yes, true otherwise. Make sure to #include any header files of classes used in LinkedStack.cpp so that compiles. TileNode.h 1 #ifndef _NODE 2 #define _NODE 3 4 5 567 7 8 9 10 11 12 13 14 15 565 16 17 x 18 19 20 21 22 23 #include "Tile.h" Node class This is a node for a linked list. class TileNode{ private: Tile* data;//the data for the node TileNode* next;//the next node public: }; #endif TileNode (Tile* d);//constructor //note: there is nothing to deallocate (for a deconstructor), let the linked list take care of it. Tile* getData();//get the data of the node. TileNode* getNext();//get the next node in the linked list void setData(Tile* newData);//set the data for the node void setNext (TileNode* newNext);//set the next node LinkedStack.h x 1 #ifndef _LINKED_STACK #define _LINKED_STACK 2 3 4 #include "StackADT.h" 5 #include "Tile.h" #include "TileNode.h" 679 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 LinkedStack class, it is a subclass of the abstract class StackADT (an interface) */ class LinkedStack: public StackADT{ private: TileNode* top; //the top of the stack int count;//number of elements public: }; #endif LinkedStack();//Constructor (sets top to nullptr and count=0) ~Linkedstack(); //Deconstructor (deletes each node in the linked list) void push(Tile* elem);//push make a new node, insert at the head of the linked list with elem in it (top of the stack). Tile* pop();//pop the stack: remove the first node in the linked list, return its data. If the stack is empty, return nullptr. Tile* peek();//return the top element of the stack, do not remove the node that has the top element. int size();//return the number of elements in the stack bool isEmpty();//is the stack empty? StackADT.hx 1 2 3 4 5 6 7 */ 8 class StackADT{//An example Stack ADT coa 9 10 11 12 13. 14 15 #ifndef _STACK_ADT #define _STACK_ADT #include "Tile.h" /* 16 StackADT public: }; #endif 0;//push elem onto the top virtual void push(Tile* elem) of the stack. virtual Tile* pop() = 0;//pop the top element off the stack and return it. = virtual Tile* peek() = 0;//return the element that is on the top of the stack. virtual int size() = 0;//how many elements are in the stack? virtual bool isEmpty() = 0;//is the stack empty? 14

Step by Step Solution

3.36 Rating (152 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To implement the LinkedStack class you need to create a new file called LinkedStackcpp and include t... View full answer

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