Question
Create a class MyStack defined as follows. You must create the body for all the functions including the constructor, destructor, and other methods. Algorithm 1:
Create a class MyStack defined as follows. You must create the body for all the functions including the constructor, destructor, and other methods.
Algorithm 1: MyStack
class MyStack {
public:
MyStack();
MyStack(int capacity1);
~MyStack();
bool IsFull(); // Determine if the stack is full
bool IsEmpty(); // Determine if the stack is empty
double Pop(); // Get and remove an element from the stack
double Top(); // Only return the top of the stack
void Push(double x); // Push an element in the stack
void Display(); // Display the elements in the stack
public:
double* s;
int capacity; // Number of elements that the stack can contain
int size; // Number of elements in the stack
};
Exercise 1: Queue
Create a class `MyQueue` defined as follows. You must create the body for all the functions including the constructor, destructor, and other methods.
Algorithm 2: MyQueue
class MyQueue {
public:
MyQueue();
MyQueue(int capacity1);
~MyQueue();
bool IsFull(); // Determine if the queue is full
bool IsEmpty(); // Determine if the queue is empty
void Enqueue(double x); // Add an element in the queue
double Dequeue(); // Remove an element from the queue
double Front(); // Access the first element in the queue
double Rear(); // Get the last element in the queue
void DisplayQueue(); // Display the elements in the queue
void DisplayAll(); // Display all the elements in the queue
public:
int front, rear;
int size; // Number of elements in the queue
int capacity; // Number of elements that the queue can contain
double* q;
};
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Certainly Heres the implementation for both the MyStack and MyQueue classes include class MyStack public MyStack capacity 10 Default capacity s new do...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started