±àÒëÔ­ÀíʵÑ鱨¸æ1

- 1 -

ʵÑéÒ» ÎÄ·¨µÄ»úÄÚ±íʾÓëÊäÈëÊä³ö

ʵÑéÌâÄ¿£ºÎÄ·¨µÄ»úÄÚ±íʾÓëÊäÈëÊä³ö

ʵÑéÄ¿µÄ£ºÊäÈëÎÄ·¨£¬°´ÕÕËùÌṩµÄ¸÷ÖÖÒªÇóÊä³öËùÐè½á¹û¡£

ʵÑé×¼±¸£ºÔÚѧϰÁ˹æÔòºÍÓйØÎÄ·¨µÄһЩ»ù±¾¸ÅÄîºó£¬Óñ¾ÊµÑéÀ´¼ÓÉî¸÷¸ö¸Å

Äî¼äµÄ¹ØÏµ¡£ÀýÈç ¹æÔò¡¢ÎÄ·¨¡¢Ê¶±ð·û¡¢ChomskyÎÄ·¨¡¢ÖÕ½á·û¡¢·ÇÖÕ½á·ûµÈ¡£

Éè¼Æ¿¼ÂÇ£º

- 1 -

- 2 -

ʵÑé´úÂ룺

#include int t=0; char A[20]; struct LeftItem;

struct RightNode {

char right;

RightNode* nextsibling; RightNode* nextrule; RightNode(char abc) {

right=abc;

nextsibling=NULL;

nextrule=NULL; } };

struct LeftItem { char left;

RightNode* therule;

};

//////////////////////////////////////////////////////////////////////////////

void Insert(RightNode*& pNode,char* temp) {

pNode=new RightNode(*temp);

RightNode* qNode=pNode;

temp++;

while(*temp!='\\0')

{

qNode->nextsibling=new

RightNode(*temp);

qNode=qNode->nextsibling;

temp++;

}

}

void Bianli1(LeftItem Array[],int length,RightNode*

pNode)

{

RightNode* qNode=pNode->nextrule;

while(pNode!=NULL)

{

for(int i=0;i

{

- 2 -

if(pNode->right==Array[i].left)

break;

}

if(i==length) {

for(i=0;iright==A[i]) break; } if(i==t) { if(i!=0) cout<<\

cout<right;

A[t]=pNode->right;

t++; } }

pNode=pNode->nextsibling;

}

if(qNode!=NULL)

Bianli1(Array,length,qNode);

}

void Bianli2(RightNode* pNode) {

RightNode* qNode=pNode->nextrule;

while(pNode!=NULL)

{

cout<right;

pNode=pNode->nextsibling;

}

if(qNode!=NULL)

{

cout<<\

Bianli2(qNode);

}

}

void SelectMenu(LeftItem Array[],int length) {

int sel2;

do

{

- 3 -

cout<<\ÇëÑ¡ÔñÄúÒª²éѯµÄÏîÄ¿.\ cout<<\²éѯȫÌ广ÔòÇë°´------> 1\

cout<<\²éѯָ¶¨¹æÔòÇë°´------> 2\

cin>>sel2; }while(sel2!=1&&sel2!=2); if(sel2==1) { for(int i=0;i

}

} else { char temp; int k;

cout<>temp;

for(int i=0;i

}

}

if(i==length) cout<<\±¾ÎÄ·¨¹æÔòÖÐûÓжÔÓ¦µÄ¹æÔò!\

else { cout<

}

}

}

//////////////////////////////////////////////////////////////////////////////

- 3 -

void main() {

char temp[20]; int size=0; int k,sel,m,n,j;

cout<<\ÇëÊäÈëÎÄ·¨¹æÔòµÄÊýÄ¿£º\ cin>>n;

LeftItem* Array=new LeftItem[n]; for(int i=0;i

cout<<\ÇëÊäÈëÎÄ·¨¹æÔò:\ cin>>temp;

if(*temp==NULL) break;

for(j=0;j

k=j; break;

}

}

if(j==size) { Array[size].left=*temp;

Insert(Array[size].therule,temp+4); size++;

}

else { RightNode* t=Array[k].therule; while(t->nextrule!=NULL) t=t->nextrule;

Insert(t->nextrule,temp+4); }

}

cout<<\

ÎÄ

·¨

¹æ

Ôò

´æ

´¢

±Ï!\

cout<<\»¶Ó­½øÈë²éѯϵͳ!\ aaa: cout<

cout<<\ÇëÑ¡ÔñÄúÒª²éѯµÄÏîÄ¿.\

Íê

ÁªÏµ¿Í·þ£º779662525#qq.com(#Ìæ»»Îª@) ËÕICP±¸20003344ºÅ-4