-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.h
More file actions
96 lines (82 loc) · 1.59 KB
/
stack.h
File metadata and controls
96 lines (82 loc) · 1.59 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
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
96
#ifndef stack_h
#define stack_h
#include"List.h"
template<class DATATYPE>
class stack
{
public:
stack();
~stack();
bool isEmpty();
bool push(DATATYPE newData);
DATATYPE pop();
bool contains(DATATYPE target);
void printStack();
DATATYPE top();
bool clearList();
void reverseStack();
//this uses my List.h and ListNode.h classes that I made. these interface with them
//this is so I can rely on one generalized templated linked list, then I can make tweeks to this
private:
List<DATATYPE>* head;
};
template<class DATATYPE>
stack<DATATYPE>::stack()
{ // new List
head = new List<DATATYPE>();
}
template<class DATATYPE>
stack<DATATYPE>::~stack()
{ //empties list in list.h
head->makeEmpty();
}
template<class DATATYPE>
bool stack<DATATYPE>::isEmpty()
{
return head->isEmpty();
}
template<class DATATYPE>
bool stack<DATATYPE>::push(DATATYPE newData)
{
return head->pushFront(newData);
}
template<class DATATYPE>
DATATYPE stack<DATATYPE>::pop()
{
return head->popFront();
}
template<class DATATYPE>
bool stack<DATATYPE>::clearList()
{
if(head != NULL)
{
head->makeEmpty(); //deletes all node
head == NULL; //sets points to NULL
return true;
}
else
return false;
}
template<class DATATYPE>
DATATYPE stack<DATATYPE>::top()
{
return head->top();
}
template<class DATATYPE>
void stack<DATATYPE>::printStack()
{
head->printList();
}
template<class DATATYPE>
void stack<DATATYPE>::reverseStack()
{
List<DATATYPE>* newList = new List<DATATYPE>();
DATATYPE temp = NULL;
while(!head->isEmpty() != NULL)
{
temp = head->popFront();
newList->pushFront(temp);
}
head = newList;
}
#endif