• 大小: 15KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-28
  • 语言: C/C++
  • 标签: c语言  

资源简介

栈实现中缀表达式到后缀表达式的转换 InfixToSuffix 用C语言编写 code blocks开发

资源截图

代码片段和文件信息

//InfixToSuffix.c
//author:081110101
//time:2009\5\21

#include “InfixToSuffix.h“

void MakeNullStack(Stack1 *s1Stack2 *s2)
{
    s1->top=s2->top=-1;
}

int Judge(char chStack1 *s1Stack2 *s2)
{
    int i;
    switch(ch)
    {

        case ‘+‘:
        {
            if(s1->data[s1->top]==‘-‘||s1->data[s1->top]==‘*‘||s1->data[s1->top]==‘/‘)
            {
                s2->data[++s2->top]=s1->data[s1->top--];
                s1->data[++s1->top]=ch;
            }
            else
            {
                s1->data[++s1->top]=ch;
            }
            return 1;
        }

        case ‘-‘:
        {
              if(s1->data[s1->top]==‘+‘||s1->data[s1->top]==‘*‘||s1->data[s1->top]==‘/‘)
              {
                    s2->data[++s2->top]=s1->data[s1->top--];
                    s1->data[++s1->top]=ch;
               }
               else
               {
                     s1->data[++s1->top]=ch;
               }
               return 1;
        }
        case ‘*‘:
        {
            if(s1->data[s1->top]==‘/‘)
            {
                s2->data[++s2->top]=s1->data[s1->top--];
                s1->data[++s1->top]=ch;
            }
            else
            {
                s1->data[++s1->top]=ch;
            }
            return 1;
        }

        case ‘/‘:
        {
            if(s1->data[s1->top]==‘*‘)
            {
                s2->data[++s2->top]=s1->data[s1->top--];
                s1->data[++s1->top]=ch;
            }
            else
            {
                s1->data[++s1->top]=ch;
            }
            return 1;
        }
        case ‘)‘:
        {
            i=s1->top;
            while(s1->data[i]!=‘(‘ && i>=0)
            {
                i--;
            }
            if(i==-1)
            {
                return 0;
            }
            while(s1->data[s1->top]!=‘(‘)
            {
                s2->data[++s2->top]=s1->data[s1->top--];
            }
            s1->top--;
            return 1;
        }
 }
 }

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      23034  2009-05-21 23:44  InfixToSuffix\bin\Debug\InfixToSuffix.exe

     文件       2095  2009-05-21 23:44  InfixToSuffix\InfixToSuffix.c

     文件       1208  2009-05-21 23:44  InfixToSuffix\InfixToSuffix.cbp

     文件        591  2009-05-21 23:44  InfixToSuffix\InfixToSuffix.depend

     文件        469  2009-05-21 23:43  InfixToSuffix\InfixToSuffix.h

     文件        449  2009-05-21 23:44  InfixToSuffix\InfixToSuffix.layout

     文件       1325  2009-05-21 23:43  InfixToSuffix\main.c

     文件       5535  2009-05-21 23:44  InfixToSuffix\obj\Debug\InfixToSuffix.o

     文件       5687  2009-05-21 23:43  InfixToSuffix\obj\Debug\main.o

     文件       5519  2009-05-21 23:43  InfixToSuffix\obj\Debug\stack.o

     目录          0  2009-05-21 23:44  InfixToSuffix\bin\Debug

     目录          0  2009-05-21 23:44  InfixToSuffix\obj\Debug

     目录          0  2009-05-19 23:06  InfixToSuffix\bin

     目录          0  2009-05-19 23:06  InfixToSuffix\obj

     目录          0  2009-05-21 23:44  InfixToSuffix

----------- ---------  ---------- -----  ----

                45912                    15


评论

共有 条评论

相关资源