Class LinkedStack The next class you will be implementing is the linked-list based stack itself, it...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 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
Expert Answer:
Answer rating: 100% (QA)
To implement the LinkedStack class you need to create a new file called LinkedStackcpp and include t... View the full answer
Related Book For
Posted Date:
Students also viewed these accounting questions
-
This is a puzzlejust for fun. Lewis Carroll (1832-1898), author of Alice in Wonderland and Through the Looking Glass, was a mathematician, logician, and political scientist. Carroll loved careful...
-
This is a question for my statistics class, please help me solve it. Thanks! 6. Which of the following about the random variables and probability distributions is a true statement? Explain why other...
-
Show that this is a basis for R4. (We can use the results of this subsection to simplify this job.) 0000
-
Donna is a Malaysian tax resident, working as a manager in the human resource department of a telecommunication company. Her remuneration yearly salary amounted to RM82,860. Her husband, Don service...
-
A subtle form of racial discrimination in housing is racial steering. Racial steering occurs when real estate agents show prospective buyers only homes in neighborhoods already dominated by that...
-
A wire is stretched between two posts. Another wire is stretched between two posts that are twice as far apart. The tension in the wires is the same, and they have the same mass. A transverse wave...
-
The mean square error criterion for ridge regression is \[ E\left(L_{1}^{2} ight)=\sum_{j=1}^{p} \frac{\lambda_{j}}{\left(\lambda_{j}+k ight)^{2}}+\sum_{j=1}^{p} \frac{\alpha_{j}^{2}...
-
An air-standard Diesel cycle has a compression ratio of 16 and a cutoff ratio of 2. At the beginning of the compression process, air is at 95 kPa and 27C. Accounting for the variation of specific...
-
Assembly Line with Indexed Components What happen if we need two specific components to start the service (index has to match)? E.g., assembling of a car with both left and right doors. Assume the...
-
The comparative statements of Wahlberg Company are presented here. All sales were on account. Net cash provided by operating activities for 2017 was $220,000. Capital expenditures were $136,000, and...
-
REQUIRED: Use Excel to prepare an electronic spreadsheet of an accounts receivable aging report for Garret for April 30. Organize spreadsheet with the following columns heading above. Revenue and...
-
Legal challenges of taxing pensions and annuities in IR4.0 era Overview: Discuss the relevant section from Income Tax Act 1967 (in respect of the topic) and overview of IR4.0. Discussion the legal...
-
Your objective is to write an properly formatted, error-free business document.You may choose your own subject for the communication, keeping in mind to use the proper approach for the intended...
-
A well-formatted, error-free business document is your goal.For the communication, choose your own subject, keeping in mind the intended audience and the appropriate approach. The following types of...
-
Financial institutions, such as the Banking systems...Create a report that focuses on the data used to support the operation of your organization in your case study and answer the following...
-
Earn up to 50 pts per FULL 2 page typewritten paper by responding to the question: "What happened in the news within the last 30 days where business law is impacted, and discuss the legal...
-
5. Premium Patty is considering setting up a shop in Champaign, IL. Their plan can be divided into 3 stages. Stage 1: The project requires a test marketing expense of $200,000. This test market is...
-
An auto-parts manufacturer is considering establishing an engineering computing center. This center will be equipped with three engineering workstations each of which would cost $25,000 and have a...
-
Burts utility function is U(x1, x2) = (x1 +2)(x2 +6), where x1 is the number of cookies and x2 is the number of glasses of milk that he consumes. (a) What is the slope of Burts indifference curve at...
-
The Miss Manners Refinery in Dry Rock, Oklahoma, converts crude oil into gasoline. It takes 1 barrel of crude oil to produce 1 barrel of gasoline. In addition to the cost of oil there are some other...
-
Four students, Art, Bob, Cal, and Dan, must be assigned rooms in a college dorm. The dean of housing would like to assign them in stable partnerships, so that no two students would prefer each other...
-
A traveller walks \(30 \mathrm{~m}\) along a train platform, dragging their suitcase behind them using a strap attached to the top. The traveller's hand is \(0.25 \mathrm{~m}\) above the top of the...
-
You have lost your skateboard, so you choose to walk around the various sections of the local skate park. The coefficient of static friction between your shoes and the concrete surface is 0.53 . What...
-
A positively charged particle creates the electric field shown in Figure 30. 20. When the kinks in the electric field lines reach the rod, what is the direction of the current induced in the rod?...
Study smarter with the SolutionInn App