-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDefineTemplate.cpp
74 lines (54 loc) · 1.19 KB
/
DefineTemplate.cpp
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
// 2019, 11/25, 19:30, by Queenie
// Template Func
// Template Class
// this file extension shall be .h
#include <stdio.h>
#include <stdlib.h>
#include <list>
// template <typename TypeVar>;
// 從以往的值變成型態作為值
// typename 為型別名稱
// 上述的 Type 為通用型態的指示元,是變數容器的名稱
#ifdefine STACK_H_
#define STACK_H_
template<typename TypeVar>
class Stack{
private:
enum {MAX=10}; // constant: Class
TypeVar items[MAX] = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; // item holder
int top; // index
public:
Stack();
bool isFull() const;
bool isEmpty() const;
bool pop(int& item);
};
// 加入關鍵字
template <typename TypeVar>
bool Stack::isEmpty(){
return top == 0;
};
// 加入關鍵字
template <typename TypeVar>
bool Stack::isFull(){
return top == MAX;
};
// 加入關鍵字
template <typename TypeVar>
bool Stack::pop(const TypeVar& item){
if(top > 0)
{
item = items[--top];
return true;
}
else
return false;
};
Stack st;
int main() {
st.isEmpty();
st.isFull();
st.pop(88);
return 0;
}
#endif