-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.h
More file actions
58 lines (49 loc) · 1.12 KB
/
stack.h
File metadata and controls
58 lines (49 loc) · 1.12 KB
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
58
#ifndef STACK
#define STACK
#include "singlylist.h"
/**
* @brief Template Stack Container
*
* @tparam T Type parameter
*/
template <class T>
class Stack {
public:
Stack() : container(new SinglyList<T>()) {}
Stack(const Stack& copy) { container = copy.container; }
~Stack() { delete container; }
/**
* @brief Add item to the stack
*
* @param item item to add
*/
void Push(T item) { container->InsertAtBack(item); }
/**
* @brief Remove an item from the stack
*
*/
void Pop() { container->DeleteAtBack(); }
/**
* @brief Get the item at the top of the stack
*
* @return T type of the item
*/
T Peek() { return container->GetTail()->data; }
/**
* @brief Get the Size object
*
* @return size_t number of items in the stack
*/
size_t Size() const { return container->Size(); }
/**
* @brief Checks for the empty
*
* @return true if the size greater than 0
* @return false otherwise
*/
bool IsEmpty() { return Size() == 0 ? true : false; }
private:
// using linked list implementation for the underlying container
SinglyList<T>* container;
};
#endif