-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathStack.cpp
More file actions
90 lines (70 loc) · 1.43 KB
/
Copy pathStack.cpp
File metadata and controls
90 lines (70 loc) · 1.43 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Stack.cpp: implementation of the Stack class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "RenLib.h"
#include "Stack.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
Stack::Stack() :
m_nIndex(0)
{
const Item NullItem = {0, NULL};
for (int i=0; i < SIZE; i++)
{
m_Stack[i] = NullItem;
}
}
Stack::~Stack()
{
}
bool Stack::IsEmpty()
{
return (m_nIndex == 0);
}
void Stack::Push(int nMove, MoveNode* pMove)
{
VERIFY(m_nIndex < SIZE);
m_Stack[m_nIndex].nMove = nMove;
m_Stack[m_nIndex].pMove = pMove;
m_nIndex++;
}
void Stack::Pop(int& nMove, MoveNode*& pMove)
{
VERIFY(m_nIndex > 0);
m_nIndex--;
nMove = m_Stack[m_nIndex].nMove;
pMove = m_Stack[m_nIndex].pMove;
}
void Stack::Push(MoveNode* pMove)
{
VERIFY(m_nIndex < SIZE);
m_Stack[m_nIndex].nMove = 0;
m_Stack[m_nIndex].pMove = pMove;
m_nIndex++;
}
void Stack::Pop(MoveNode*& pMove)
{
VERIFY(m_nIndex > 0);
m_nIndex--;
pMove = m_Stack[m_nIndex].pMove;
}
void Stack::Push(int nMove)
{
VERIFY(m_nIndex < SIZE);
m_Stack[m_nIndex].nMove = nMove;
m_Stack[m_nIndex].pMove = NULL;
m_nIndex++;
}
void Stack::Pop(int& nMove)
{
VERIFY(m_nIndex > 0);
m_nIndex--;
nMove = m_Stack[m_nIndex].nMove;
}