Define the exception class MemoryAllocationException and then revise the definition of the method push in the class LinkedStack so that it throws this exception if it cannot allocate a new node.
Ty in advance
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Oct 13, 2013, 6:46 PM
I don't know anything about the LinkedStack class which I assume you created in a previous project but it sounds like it is a limited to a maximum number of nodes (say maxNodes).
If you keep a count of the nodes as new ones are added (or existing ones are removed) in a variable countNodes say, then you'll need to insert something like this at the beginning of the push method:
if (countNodes == maxNodes)
{
throw new MemoryAllocationException("Maximum number of nodes for LinkedStack has been reached");
}