-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAStack.cpp
More file actions
49 lines (42 loc) · 694 Bytes
/
AStack.cpp
File metadata and controls
49 lines (42 loc) · 694 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
//array-based stack implementation
template <typename E> class AStack: public Stack<E>
{
private:
int maxSize;
int top;
E *listArray;
public:
AStack(int size =defaultSize)
{
maxSize = size;
top =0;
listArray = new E[size];
}
~AStack()
{
delete [] listArray;
}
void clear()
{
top = 0;
}
void push(const E& it)
{
Assert(top != maxSize, "stack is full");
listArray[top++] = it;
}
E pop()
{
Assert(top != 0, "stack is empty");
return listArray[--top];
}
const E& topValue() const
{
Assert(top != 0, "stack is empty");
return listArray[top-1];
}
int length() const
{
return top;
}
};