Stack is implemented using arrays. Create a new stack class that extends vector. Note that the vector is now the storage for data in the stack. A stack is a vector, because stack extends vector. Draw the UML diagram for the classes. Implement it.
```
template
class Stack
{
public:
Stack();
bool empty() const;
T peek() const;
void push(T value);
T pop();
int getSize() const;
private:
T elements[100];
int size;
};
```
```
#include
#include
using namespace std;
#ifndef STACK_H
#define STACK_H
template
class Stack: public vector
{
public:
Stack();
bool empty();
T peek();
void push(T value);
T pop();
int getSize();
};
template
Stack
{
}
template
bool Stack
{
return getSize() == 0;
}
template
T Stack
{
if (empty())
throw runtime_error("Stack is already empty");
return at(getSize() - 1);
}
template
void Stack
{
push_back(value);
}
template
T Stack
{
if (empty())
throw runtime_error("Stack is already empty");
You might also like to view...
The AddMenu action is used to reference a macro group, listing each macro as a separate option in the Shortcut Menu
Indicate whether the statement is true or false
Traffic classes map to QoS policies and assign bandwidth weight values to each policy
Answer the following statement true (T) or false (F)