stack.cpp

来自「正规(则)表达式转化为NFA」· C++ 代码 · 共 81 行

CPP
81
字号
// Stack.cpp: implementation of the Stack class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "TONFA.h"
#include "Stack.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

Stack::Stack()
{
	vec=new int[SIZE];
	maxsize=SIZE;
	top=-1;
}

Stack::~Stack()
{
	delete [] vec;
}

void Stack::Push(int state)
{
	if(top==maxsize-1)
		AfxMessageBox("Overflow");
	else
	{
		top++;
		vec[top]=state;
	}
}

int Stack::Pop()
{
	int temp;
	if(top==-1)
	{
		AfxMessageBox("underflow");
		return 0;
	}
	else
	{
		temp=vec[top];
		top--;
		return temp;
	}
}

int Stack::GetTop()
{
	if(top==-1)
	{
		AfxMessageBox("underflow");
		return 0;
	}
	else
		return vec[top];
}

void Stack::Clear()
{
	top=-1;
}

int Stack::IsEmpty()
{
	if(top==-1)
		return 1;
	else 
		return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?