forked from msdohehrty/dsa555-s16
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.h
More file actions
46 lines (45 loc) · 595 Bytes
/
Copy pathstack.h
File metadata and controls
46 lines (45 loc) · 595 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
43
44
45
46
template <typename T>
class Stack{
T* data_;
int max_;
int size_;
void grow(){
T* newdata=new T[max_+100];
for(int i=0;i<size_;i++){
newdata[i]=data_[i];
}
max_=max_+100;
delete [] data_;
data_=newdata;
}
public:
Stack(){
data_=new T[100];
max_=100;
size_=0;
}
void push(const T& data){
if(size_ >= max_){
grow();
}
data_[size_++]=data;
}
void pop(){
if(!isEmpty()){
size_--;
}
}
T top() const{
T rc;
if(!isEmpty()){
rc= data_[size_-1];
}
return rc;
}
bool isEmpty() const{
return (size_==0);
}
~Stack(){
delete [] data_;
}
}