-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathADTStack.cpp
More file actions
42 lines (38 loc) · 699 Bytes
/
Copy pathADTStack.cpp
File metadata and controls
42 lines (38 loc) · 699 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
#ifndef _ADTSTACK
#define _ADTSTACK 1
#include "ADTList.cpp"
template<typename T>
class Stack{
public:
Stack(){}
~Stack(){}
void clear(){
elem.clear();
}
bool empty(){
return elem.empty();
}
int length(){
return elem.length();
}
status getTop(T &e){
if(not length()) return ERROR;
e=*--elem.end();
return OK;
}
void traverse(){
elem.traverse();
}
void push(T e){
elem.insert(elem.end(),e);
}
status pop(T &e){
if(not length()) return ERROR;
e=*--elem.end();
elem.erase(--elem.end());
return OK;
}
private:
SquList<T>elem;
};
#endif