forked from landbroken/BasicKnowledge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray_stack.cpp
More file actions
64 lines (56 loc) · 711 Bytes
/
array_stack.cpp
File metadata and controls
64 lines (56 loc) · 711 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
57
58
59
60
61
62
63
64
#include "stdafx.h"
#include<iostream>
#include"StackDemo.h"
using namespace std;
ArrStack::ArrStack(int maxSize)
{
size = maxSize;
tos = -1;
contain = new int[size];
}
ArrStack::~ArrStack()
{
if (contain!=nullptr)
{
delete contain;
contain = nullptr;
}
}
void ArrStack::Push(const int & element)
{
if (!IsFull())
{
++tos;
contain[tos] = element;
}
}
int ArrStack::GetTop() const
{
if (!IsEmpty())
{
return contain[tos];
}
else
{
throw std::exception("NULL");
}
}
void ArrStack::Pop()
{
if (!IsEmpty())
{
tos--;
}
}
bool ArrStack::IsEmpty() const
{
return tos == -1;
}
bool ArrStack::IsFull() const
{
return tos >= size - 1;
}
void ArrStack::MakeEmpty()
{
tos = -1;
}