50 throw std::out_of_range(
"Stack overflow");
64 throw std::out_of_range(
"Stack underflow");
74 std::cout <<
stack[i] <<
"\n";
86 throw std::out_of_range(
"Stack underflow");
99 throw std::out_of_range(
"Stack underflow");
114 assert(
stack.empty());
115 assert(!
stack.full());
119 assert(
stack.topmost() == 10);
122 assert(
stack.topmost() == 20);
127 assert(
stack.full());
132 }
catch (
const std::out_of_range& e) {
133 assert(std::string(e.what()) ==
"Stack overflow");
142 assert(
stack.topmost() == 20);
143 assert(
stack.bottom() == 10);
148 assert(
stack.empty());
149 assert(!
stack.full());
154 }
catch (
const std::out_of_range& e) {
155 assert(std::string(e.what()) ==
"Stack underflow");
160 }
catch (
const std::out_of_range& e) {
161 assert(std::string(e.what()) ==
"Stack underflow");
166 }
catch (
const std::out_of_range& e) {
167 assert(std::string(e.what()) ==
"Stack underflow");
177 std::cout <<
"All tests passed!" << std::endl;
Class representation of a stack.
bool empty() const
Checks if the stack is empty.
T bottom() const
Displays the bottom element of the stack.
std::unique_ptr< T[]> stack
Smart pointer to the stack array.
T topmost() const
Displays the topmost element of the stack.
int stackIndex
Index pointing to the top element of the stack.
int stackSize
Maximum size of the stack.
Stack(int size)
Constructs a new Stack object.
bool full() const
Checks if the stack is full.
void push(T element)
Pushes an element onto the stack.
void show() const
Displays all elements in the stack.
T pop()
Pops an element from the stack.
for std::invalid_argument
void push(const value_type &item)