欢迎来到天天文库
浏览记录
ID:8391654
大小:71.00 KB
页数:17页
时间:2018-03-24
《正则分析程序实现》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、#include#include#includeusingnamespacestd;intNFASNum;//NFA状态数vectorrec;stringstr2;intAccept[100]={0};//边类classEdge{public:intnum;intpos;charweight;Edge*next;public:Edge(){num=-1;pos=-1;next=NULL;}Edge(intNum,intPos,charch){num=Num;pos=Pos;weight
2、=ch;next=NULL;}};//顶点类classVertex{public:intvnum;Vertex*next;Edge*out;public:Vertex(){vnum=-1;next=NULL;out=NULL;}Vertex(intnum){vnum=num;next=NULL;out=NULL;}};//邻接表类classAdjacentT{private:Vertex*Start;intNumV;intNumE;public:AdjacentT(){NumV=1;NumE=0;Start=newVertex();}~Adjac
3、entT(){Vertex*V;Edge*E;V=Start;for(inti=0;iout;while(E){V->out=E->next;deleteE;E=V->out;}V=V->next;}}intGetval(intpos)//得到顶点值{Vertex*V=Start;for(inti=0;inext;}returnV->vnum;}intGetpos(intval)//得到顶点位置{Vertex*V=Start;inttemp=-1;for(inti=0;i4、++){if(V->vnum==val){temp=i;break;}V=V->next;}returntemp;}charGetwei_pos(intv1,intv2)//得到边权值{charch='$';Vertex*V=Start;for(inti=0;inext;}Edge*E=V->out;while(E){if(E->pos==v2){ch=E->weight;break;}else{E=E->next;}}returnch;}charGetwei_val(intval1,intval2){returnGe5、twei_pos(Getpos(val1),Getpos(val2));}intSetval(intval,intpos)//赋予顶点值{Vertex*V=Start;for(inti=0;inext;}V->vnum=val;return0;}intInsertver(intval)//插入顶点值{intpos;pos=Getpos(val);Vertex*V=Start;while(V->next){V=V->next;}Vertex*NewV=newVertex(val);V->next=NewV;NumV++6、;return0;}intInsertedge_pos(intv1,intv2,charwei)//两定点之间插入边{Vertex*V=Start;for(inti=0;inext;}Edge*E;E=V->out;Edge*NewE=newEdge(Getval(v2),v2,wei);if(!E){V->out=NewE;NumE++;return0;}while((E->pos!=v2)&&(E->next)){E=E->next;}if(!E->next){E->next=NewE;NumE++;}return7、0;}intInsertedge_val(intval1,intval2,charwei){intv1=Getpos(val1);intv2=Getpos(val2);Insertedge_pos(v1,v2,wei);return0;}intPrint_NFA()//输出NFA{Vertex*V=Start;Edge*E=newEdge();cout<<"状态边(权值)"<vnum<<"";E=V->out;if(E){while(E){cout<<""<num8、<<"("<weight<<")";E=E->next;}}else{cout<<"ACC";}cout<
4、++){if(V->vnum==val){temp=i;break;}V=V->next;}returntemp;}charGetwei_pos(intv1,intv2)//得到边权值{charch='$';Vertex*V=Start;for(inti=0;inext;}Edge*E=V->out;while(E){if(E->pos==v2){ch=E->weight;break;}else{E=E->next;}}returnch;}charGetwei_val(intval1,intval2){returnGe
5、twei_pos(Getpos(val1),Getpos(val2));}intSetval(intval,intpos)//赋予顶点值{Vertex*V=Start;for(inti=0;inext;}V->vnum=val;return0;}intInsertver(intval)//插入顶点值{intpos;pos=Getpos(val);Vertex*V=Start;while(V->next){V=V->next;}Vertex*NewV=newVertex(val);V->next=NewV;NumV++
6、;return0;}intInsertedge_pos(intv1,intv2,charwei)//两定点之间插入边{Vertex*V=Start;for(inti=0;inext;}Edge*E;E=V->out;Edge*NewE=newEdge(Getval(v2),v2,wei);if(!E){V->out=NewE;NumE++;return0;}while((E->pos!=v2)&&(E->next)){E=E->next;}if(!E->next){E->next=NewE;NumE++;}return
7、0;}intInsertedge_val(intval1,intval2,charwei){intv1=Getpos(val1);intv2=Getpos(val2);Insertedge_pos(v1,v2,wei);return0;}intPrint_NFA()//输出NFA{Vertex*V=Start;Edge*E=newEdge();cout<<"状态边(权值)"<vnum<<"";E=V->out;if(E){while(E){cout<<""<num
8、<<"("<weight<<")";E=E->next;}}else{cout<<"ACC";}cout<
此文档下载收益归作者所有