-
Notifications
You must be signed in to change notification settings - Fork 0
/
myStack.hpp
57 lines (46 loc) · 1.62 KB
/
myStack.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//Name: Caroline Su
//Student# : A01369603
#ifndef LAB3TEMP_MYSTACK_HPP
#define LAB3TEMP_MYSTACK_HPP
class MyStack{
public:
static constexpr int SIZE = 10;
// Default constructor
// PRE: None
// POST: Stack is initialized with index set to -1 (empty)
MyStack();
// Push a number onto the stack
// PRE: number is a valid integer
// POST: If the stack is not full, number is added to the top of the stack
// RETURN: true if the number was added successfully, false if the stack is full
bool push(int number);
// Remove the top element from the stack
// PRE: The stack is not empty
// POST: The index is decremented, effectively removing the top element
// RETURN: void
void pop();
// Get the top element of the stack
// PRE: The stack is not empty
// POST: The stack remains unchanged
// RETURN: The integer at the top of the stack, or -1 if the stack is empty
[[nodiscard]] int top() const;
// Check if the stack is empty
// PRE: None
// POST: The stack remains unchanged
// RETURN: true if the stack is empty, otherwise false
[[nodiscard]] bool empty() const;
// Check if the stack is full
// PRE: None
// POST: The stack remains unchanged
// RETURN: true if the stack is full, otherwise false
[[nodiscard]] bool full() const;
// Print the contents of the stack
// PRE: None
// POST: The stack remains unchanged
// RETURN: A string representation of the stack from bottom to top
[[nodiscard]] std::string print() const;
private:
int index;
int intArray[SIZE]{};
};
#endif //LAB3TEMP_MYSTACK_HPP