-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack.cpp
More file actions
54 lines (44 loc) · 691 Bytes
/
Copy pathStack.cpp
File metadata and controls
54 lines (44 loc) · 691 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
#include<iostream>
#include<assert.h>
using namespace std;
const int Max = 100;
class Stack{
private:
int element[Max];
int top;
public:
Stack();
bool empty();
int length();
void push(int x);
int pop();
int getTop();
};
Stack::Stack()
{
top=-1;
}
bool Stack::empty()
{
return (top==-1);
}
int Stack::length()
{
return (top+1);
}
void Stack::push(int x)
{
assert(length()<Max);
element[++top]=x;
}
int Stack::pop()
{
assert(!empty());
int x = element[top--];
return x;
}
int Stack::getTop()
{
assert(!empty());
return element[top];
}