Create a class MyStack defined as follows. You must create the body for all the functions including
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: 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;
};
Smith and Roberson Business Law
ISBN: 978-0538473637
15th Edition
Authors: Richard A. Mann, Barry S. Roberts