⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 statetable.cpp

📁 正规(则)表达式转化为NFA
💻 CPP
字号:
// StateTable.cpp: implementation of the StateTable class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "TONFA.h"
#include "StateTable.h"

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

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

StateTable::StateTable()
{
	for(int i=0;i<TABNUM;i++)
	{
		tableList[i].count=0;
		tableList[i].next=NULL;
		tableList[i].tail=NULL;
		tableList[i].point.x=tableList[i].point.y=-1;
	}
}

StateTable::~StateTable()
{
	ListNode * p,*temp;
	for(int i=0;i<TABNUM;i++)
	{
		p=tableList[i].next;
		while(p!=NULL)
		{
			temp=p;
			p=p->next;
			delete temp;
		}
		
	}
}
void StateTable::Insert(int startState,int endState,char a)
{//startState表示初态,endstate表示接受状态
	ListNode * currptr;
	currptr=new ListNode(endState,a,NULL);
	if(tableList[startState].next==NULL)
	{
		tableList[startState].next=currptr;
		tableList[startState].tail=tableList[startState].next;
	}
	else
	{
		tableList[startState].tail->next=currptr;
		tableList[startState].tail=currptr;
	}
	tableList[startState].count++;
}

void StateTable::ClearTable()
{
	ListNode * p,*temp;
	for(int i=0;i<TABNUM;i++)
	{
		p=tableList[i].next;
		while(p!=NULL)
		{
			temp=p;
			p=p->next;
			delete temp;
		}
		tableList[i].count=0;
		tableList[i].next=NULL;
		tableList[i].tail=NULL;
		tableList[i].point.x=tableList[i].point.y=-1;
	}
}

⌨️ 快捷键说明

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