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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Oct 13, 2013, 2:46 PM EDT
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");
}