zoukankan      html  css  js  c++  java
  • 有限自动机的构造与识别

    #include<stdio.h>
    #define N 30
    char str[N]={NULL};
    int st[N];
    int t=0,k=0,a,t1=0;
    struct node//定义一个队列
    {
        char data;
        struct node * next;
    };
    typedef struct node QueueNode;
    struct node2//定义一个链队列
    {
        QueueNode *front;
        QueueNode *rear;
    };
    typedef struct node2 Queue;
    Queue InitQueue()//初始化队列
    {
        Queue Q;
        Q.front=(QueueNode *)malloc(sizeof(QueueNode));
        Q.front->next=NULL;
        Q.rear=Q.front;
        return(Q);
    }
    Queue InserQ(Queue Q,char x)//x进队列
    {
        QueueNode *p;
        p=(QueueNode *)malloc(sizeof(QueueNode));
        p->data=x;
        p->next=NULL;
        Q.rear->next=p;
        Q.rear=p;
        return(Q);
    }
    Queue DeleteQ(Queue Q)//出队列
    {
        int i=t++,j;
        QueueNode *p;
        char y;
        if(Q.front==Q.rear)
        {
            printf("队列为,无法出队列!");//判断队列是否为空
            return(Q);
        }
        p=Q.front->next;
        y=Q.front->next->data;//将队列中的元素赋值给y
        Q.front->next=p->next;
        if(p==Q.rear)
            Q.rear=Q.front;
        str[i]=y;//存储单个字符
        st[k]=i;//存储位置
        if(y==' ');
        if(y=='*'||y=='|')
        {
            //if(y=='*')
                //str[i]=y;
            if(str[0]!=NULL)//如果数组str非空,则输出
                Print(0,str[0]);
            t=0;
            //continue;
        }
       /*if((y>='A'&&y<='Z')||(y>='a'&&y<='z'))//利用ASCII判断y是否是属于字母,并存储在数组str中
       {
            str[i]=y;
       }*/
       k++;
        free(p);
        return Q;
    }
    void Print(int i,char y);//调用函数来判断并输出
    main()
    {
        char x,y;
        Queue p,q;
        p=InitQueue();
        printf("请输入正规式:");
        while(scanf("%c",&x)==1&&x!='\n')
            p=InserQ(p,x);
        q=p;
        while(p.front!=p.rear)
            p=DeleteQ(p);
      
    }
    void Print(int i,char y)
    {
        a=st[i+1]+1;
        if(y=='|'||y=='*')
        {
            k--;
            return;
        }
        if(str[i]!='|')
            a=t1++;
        if(str[i+1]=='*')
        {
            printf("f(%d,%c)=%d\n",i,'~',k);
            printf("f(%d,%c)=%d\n",k,y,k);
            printf("f(%d,%c)=%d\n",k,'~',a);
        }
        else
            printf("f(%d,%c)=%d\n",i,y,st[i+1]);
        if(i<t)
            Print(i+1,str[i+1]);
        memset(str,0,N);//清空数组str里的所有元素
    }
  • 相关阅读:
    DevOps、CI、CD都是什么鬼?
    卧槽!华为《Linux中文手册》火了,完整版 PDF 开放下载!
    MongoDB 常用运维实践总结
    谈谈变更过程中的运维意识
    Ping原理详解
    为什么Redis要比Memcached更火?
    一篇文章教你搞懂日志采集利器 Filebeat
    工程师姓什么很重要!别再叫我“X工”!!!
    这些 Shell 分析服务器日志命令集锦,收藏好
    Linux下找出吃内存的方法总结
  • 原文地址:https://www.cnblogs.com/severusandsusa/p/6150454.html
Copyright © 2011-2022 走看看