-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSeqstack.cpp
More file actions
56 lines (56 loc) · 892 Bytes
/
Seqstack.cpp
File metadata and controls
56 lines (56 loc) · 892 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
47
48
49
50
51
52
53
54
55
56
#include<iostream>
using namespace std;
const int StackSize = 1024;
template<class T>
class Seqstack
{
public:
Seqstack() { top = -1;}
void Push(T x);
T Pop();
T GetTop();
bool Empty();
private:
T data[StackSize];
int top;
};
template<class T>
bool Seqstack<T>::Empty()
{
return -1 == top ? true : false;
}
template<class T>
void Seqstack<T>::Push(T x)
{
if (top >= StackSize - 1) throw"ÉÏÒç";
top++;
data[top] = x;
}
template<class T>
T Seqstack<T>::Pop()
{
if (Empty()) throw"ÏÂÒç";
top--;
return data[top + 1];
}
template<class T>
T Seqstack<T>::GetTop()
{
if (Empty()) throw"ÏÂÒç";
return data[top];
}
//void main()
//{
// Seqstack<int> S;
// int a[5] = { 1,2,3,4,5 };
// for (int i = 0;i < 5;i++)
// {
// S.Push(a[i]);
// cout << S.GetTop() << " ";
// }
// S.Pop();
//
// cout << S.GetTop() << " ";
//
//
//}