Write a class called MyStack ,

Write a class called MyStack, that uses a Linked List to store unique integer values and acts like Stack.

This custom class, unlike the standard stack, must have a fixed max size that gets set via a constructor, or default to 10. The class should have its own Node struct, also Exception struct. Whenever the user tries to pop()/top() from an empty stack, or push() a value to a stack with the max size reached, the program should then throw an exception with a meaningful description. Below is how the class would look like:

Note: Exceptions should be thrown from inside the class’s functions – called functions (example: pop), and handled from the driver’s function – calling functions(example: main).

class MyStack

struct MyNode
int mValue;
MyNode* mNext = nullptr;
MyNode(int aValue) { mValue = aValue; }
struct MyException
string mDescription;
MyException(string aDescription) { mDescription = aDescription; }

MyStack(); // default constructor
MyStack(int aSize); // custom constructor
~MyStack(); // destructor
void Pop(); // removes an item (LIFO)
void Push(int aValue); // adds an item (LIFO)
int Top(); // returns a copy of an item (LIFO)
bool IsEmpty(); // returns true/false

MyNode* mHead; // head of linked list
unsigned int mMaxSize; // size of linked list

Place this order or similar order and get an amazing discount. USE Discount code “GET20” for 20% discount

Posted in Uncategorized