資源簡(jiǎn)介
C語(yǔ)言的后綴式轉(zhuǎn)中綴式實(shí)現(xiàn)
自己寫(xiě)的,希望能幫助大家
代碼片段和文件信息
#include?
#include?
int?First(char?s1[]char?s2[]);
main()
{
int?ij=0top=-1;
char?s[50][200]cstack[50][200]temp[200]temp1[50][200];
for(i=0;i<50;i++)
stack[i][0]=‘\0‘;
while(c!=EOF)
{
for?(i=0;(c=getchar())!=‘?‘&&c!=EOF&&c!=‘\n‘;i++)
s[j][i]=c;
s[j][i]=‘\0‘;
if(strlen(s[j])>0)
j++;
}
????for(i=0;i {
if(strcmp(s[i]“+“)==0||strcmp(s[i]“-“)==0||strcmp(s[i]“*“)==0||strcmp(s[i]“/“)==0)
{
if(strstr(stack[top-1]“+“)!=NULL||strstr(stack[top-1]“-“)!=NULL||strstr(stack[top-1]“*“)!=NULL||strstr(stack[top-1]“/“)!=NULL)
{
if(First(s[i]temp1[top-1])>0)
{
strcpy(temp“(“);
strcat(tempstack[top-1]);
strcat(temp“)“);
strcpy(stack[top-1]temp);
}
}
if(strstr(stac
評(píng)論
共有 條評(píng)論