-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stack.h
95 lines (74 loc) · 2.01 KB
/
Stack.h
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//
// Author: Andrew Hughes, modified comments and layout by Christian Evans
//
#ifndef AFOUR_STACK_H
#define AFOUR_STACK_H
#include <stdexcept>
typedef int Entry;
class DNode {
public:
Entry value;
DNode* next;
DNode* prev;
}; // DNode class
class Stack {
private:
DNode* _ptr;
int _size, _newstack;
// helper function for deleting the stack
void deleteList(DNode* head);
// helper function for copying the stack
void copyList(DNode* head, DNode* og);
public:
Stack();
/**
* Copy constructor:
* Create a deep copy of the other Stack
* @param other - other Stack to copy from.
*/
Stack(const Stack& other);
/**
* Copy assignment operator:
* Create a deep copy of the other Stack
* @param other - other Stack to copy from.
* @return reference to this.
*/
Stack& operator=(const Stack& other);
/**
* Destructor:
* Clean up all memory used.
*/
~Stack();
/**
* push:
* Insert the value to the top of the Stack
*
* @param Entry value – value of type Entry to add to Stack.
*/
void push(const Entry& value);
/**
* pop:
* Remove the value to the top of the Stack and return a copy.
* This function should throw an error if the Stack is empty.
*
* @return Entry value – value of type Entry that was removed from Stack
*/
Entry pop();
/**
* peek:
* Returns a copy of the value on the top of the Stack
* This function should throw an error if the Stack is empty.
*
* @return Entry value – value of type Entry that was on top of Stack
*/
Entry peek() const;
/**
* isEmpty:
* Returns whether or not the Stack is empty
*
* @return true: no values are stored in the Stack
* false: one or more values are stored in the Stack
*/
bool isEmpty() const;
};
#endif //AFOUR_STACK_H