zoukankan      html  css  js  c++  java
  • 自动机转换 248

    #include<stdio.h>
    #define N 30
    char str[N]={NULL};
    void Print(int i,char y);
    int st[N];
    int t=0,k=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=NULL;
        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[t]=y;
        st[k]=t;
        if(y!='|')
        {
            if(p->next->data=='*'&&p->next!=NULL)
            {
                str[t]='~';
                Print(0,'~');
                str[t+1]=y;
                Print(t,y);
                str[t+2]='~';
                k--;
                Print(t,'~');
                free(p->next);
            }
            else
                Print(i,y);
        }
        if(y=='|')
        {
            k--;
            t--;
        }
        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)//调用函数来判断并输出
    {
        printf("f(%d,%c)=%d\n",i,y,st[k]);
    
        memset(str,0,N);//清空数组str里的所有元素
    }
  • 相关阅读:
    SpringBoot 部署 docker 打包镜像
    Android上dip、dp、px、sp等单位说明(转)
    mac下svn问题——“.a”(静态库)文件无法上传解决
    Mac OS X 访问 Windows 共享文件夹
    svn不能添加.a文件的解决方法
    UIView的剖析(转)
    mac 下真机调试 android 手机
    IOS-synthesize和dynamic的异同(转)
    IOS学习笔记之关键词@dynamic
    【转】APNs消息推送完整讲解
  • 原文地址:https://www.cnblogs.com/YY0302/p/6144289.html
Copyright © 2011-2022 走看看