資源簡介
自己用C語言做的NFA到DFA的轉換
有較為詳細的備注,希望有所幫助。

代碼片段和文件信息
#include?“hh.h“
#include?“fun.h“
////////////////////////////檢查操作////////////////////////////////////
///檢查weight字符是否已經存在在chars字符串中,是返回1,否返回0
int?ischarok(char?weightchar?chars[])
{
int?i=0;
for(;i<(int)strlen(chars);i++)
{
if(weight==chars[i])?return?1;
}
return?0;
}
///檢查狀態集是否已經標記返回序號
int?isexist(TableNode?TN[]char?chars[])
{
for(int?i=0;i {
if(strcmp(TN[i].chchars)==0)
return?i;
}
return?0;
}
//////////////////////////////////////////////////////////////////////
///////////////////////////////////圖操作////////////////////////////////////?
void?Insert_Vertex(Graph?gchar?vertex)
{//插入新的頂點
g->NodeTable[g->NumVertex].data=vertex;
g->NodeTable[g->NumVertex].adj=NULL;
g->NumVertex++;
}?
void?Insert_Edge(Graph?gchar?v1char?v2char?weight)
{//插入邊
Edge?p;
p=(Edge)malloc(sizeof(struct?edge));
p->cost=weight;
p->dest=v2;
p->link=g->NodeTable[v1-48].adj;
g->NodeTable[v1-48].adj=p;?
}?
void?Construct_Graph(Graph?gchar?chars[])
{//創建圖
int?edgenvexn;
char?i;
char?headtail;
char?weight;
g->NumVertex=0;
g->NumEdge=0;
g->MaxNumVertex=MAX;
g->NodeTable=(Vertex)malloc((g->MaxNumVertex)*sizeof(struct?vertex));
printf(“輸入NFA狀態數:“);
flushall();
scanf(“%d“&vexn);
while(vexn<=0){
printf(“狀態數必須>0請重新輸入:\n“);
scanf(“%d“&vexn);
flushall();
}
vexn+=48;//轉化成字符串形式
for(i=‘0‘;i Insert_Vertex(gi);
}
????printf(“輸入NFA的邊數:“);
????scanf(“%d“&edgen);
while(edgen<=0){
printf(“邊數必須>0請重新輸入:\n“);
scanf(“%d“&edgen);
}
????printf(“輸入?起始狀態,接受字符?和?到達狀態:\n“);
????flushall();
//依次獲取邊的信息(起始頂點,接受字符,到達的頂點),并將這些邊插入圖中
for(i=0;i {???
flushall();
scanf(“%c?%c?%c“&tail&weight&head);
while(tail<‘0‘||tail>=vexn||head<‘0‘||head>=vexn)
{
printf(“不存在此狀態,請重新輸入\n“);
scanf(“%c?%c?%c“&tail&weight&head);
}
while(!ischarok(weightchars))//判斷是否存在該狀態
{
printf(“字符集中不存在該字符,請重新輸入\n“);
scanf(“%c?%c?%c“&tail&weight&head);
}
Insert_Edge(gtailheadweight);
}
}?
void?Destruct_Graph(Graph?g)
{//銷毀圖??
int?i;
Edge?p;
for(i=0;iNumVertex;i++)
{
p=g->NodeTable[i].adj;
while(p!=NULL)
{
g->NodeTable[i].adj=p->link;
p->link=NULL;
free?(p);
p=g->NodeTable[i].adj;
}
}
g->NumEdge=0;
g->NumVertex=0;
printf(“圖已銷毀\n“);
}
???????????????????????????????????????????????????????????????????????????????????????
void?Show_Graph(Graph?g)
{//顯示圖???
int?i;?
Edge?p;
for(i=0;iNumVertex;i++)
{
p=g->NodeTable[i].adj;
while(p!=NULL)
{
printf(“<%c%c%c>“g->NodeTable[i].datap->costg->NodeTable[p->dest-48].data);
p=p->link;
}
printf(“\n“);
}
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////狀態轉換操作////////////////////////////////////
void?BubbleSort(char?a[])
{//冒泡排序
int?ij;
char?temp;
int?len=strlen(a);
for(i=0;i {
for(j=0;j
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????15571??2011-05-14?22:25??t3\Debug\fun.obj
?????文件???????3507??2011-05-14?22:25??t3\Debug\main.obj
?????文件?????188462??2011-05-14?22:25??t3\Debug\t3.exe
?????文件?????246084??2011-05-14?22:25??t3\Debug\t3.ilk
?????文件?????231736??2011-05-14?22:25??t3\Debug\t3.pch
?????文件?????467968??2011-05-14?22:25??t3\Debug\t3.pdb
?????文件??????50176??2011-05-14?22:25??t3\Debug\vc60.idb
?????文件??????53248??2011-05-14?22:25??t3\Debug\vc60.pdb
?????文件???????5683??2011-05-14?22:32??t3\fun.cpp
?????文件????????852??2011-05-11?03:12??t3\fun.h
?????文件???????1117??2011-05-14?22:25??t3\hh.h
?????文件????????521??2011-05-14?22:32??t3\main.cpp
?????文件???????4413??2011-04-27?20:08??t3\t3.dsp
?????文件????????512??2011-04-27?19:46??t3\t3.dsw
?????文件??????58368??2011-05-14?22:32??t3\t3.ncb
?????文件??????48640??2011-05-14?22:32??t3\t3.opt
?????文件???????1274??2011-05-14?22:25??t3\t3.plg
?????目錄??????????0??2011-05-14?22:25??t3\Debug
?????目錄??????????0??2011-05-14?22:32??t3
-----------?---------??----------?-----??----
??????????????1378132????????????????????19
- 上一篇:C++衛星定位程序--通過衛星星歷確定衛星位置
- 下一篇:C語言電子地圖信息管理系統
評論
共有 條評論