-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack.cpp
More file actions
42 lines (34 loc) · 946 Bytes
/
Stack.cpp
File metadata and controls
42 lines (34 loc) · 946 Bytes
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
#include "Stack.h"
// Default Constructor for the Stack class
Stack::Stack() {}
// Pushes card with name and cost to the stack
void Stack::push(const std::string& name, int cost) {
cardList.addCard(name, cost); // Call the CardList's method to add a card
}
// Pops card from the stack if it is not empty
void Stack::pop() {
if (!isEmpty()) {
cardList.removeCard();
}
else {
std::cout << "Stack is empty. No cards to remove.\n";
}
}
// Checks if the stack is empty
bool Stack::isEmpty() const {
return cardList.isEmpty();
}
// Get the size of the stack
int Stack::getSize() const {
return cardList.getSize();
}
// Method to print all the cards in the stack
void Stack::printCards() const {
cardList.listAllCards();
}
// Returns the top card of the stack without removing it
std::pair<std::string, int> Stack::peekCard() const {
return cardList.peek();
}
// Destructor
Stack::~Stack() {}