This is the outline for the C++ code First class is Link, which should contain:
ID: 3624581 • Letter: T
Question
This is the outline for the C++ code
First class is Link, which should contain:
o An integer variable
o A pointer to itself. The class definition should be like:
class Link {
public:
int m_iData;
Link *m_pNext;
}
o Of course, it’s recommended to declare the member variables as private or protected, but you can use them as public at the beginning.
o The constructor will take one input as a parameter, which should be copied to m_iData. You should initialize m_pNext to null in the constructor.
- First class is LinkedStack, which should include:
o Link *m_pHead that points the head link in the list. Should initialize to null at the beginning.
o Push method
? Inputs and outputs?
? Input is an integer, output is … nothing or define whatever you want.
? Insert operation in the linked list. Always insert in the head.
? You don’t want to get the input as a link because a user is not supposed to know whether you implemented with a list or an array.
? It means you need to make a new Link in the Push method. How? Use new operator.
? Link *newLink = new Link(data);
? Then, reuse the insert code in the linked list.
? newLink->next = m_pHead;
? m_pHead = newLink;
o Pop method
? You need to get the head link.
? Link *link = m_pHead;
? m_pHead = m_pHead->m_pNext;
? Then save the data into a temporary integer variable.
? CAUTION !! Since you allocated a memory with the new operator, you have to get rid of the memory for yourself. Use the delete operator and finally return the integer.
? What if there is nothing in the stack?
? Why don’t you make another function IsEmpty() and call Pop method when the stack is not empty?
o Destructor
? Very important. When the stack has to be destroyed, you need to follow the link and get rid of each Link.
Explanation / Answer
Please give me the points I really need them :) I appreciate
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.