Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Smith and Roberson Business Law

Authors: Richard A. Mann, Barry S. Roberts

15th Edition

1285141903, 1285141903, 9781285141909, 978-0538473637

More Books

Students also viewed these Programming questions