?? chang.h
字號:
#include<stdio.h>
#include<string.h>
#define MaxSize 100
typedef char DataType;
#include"SeqStack.h"
int Chang(char str[],int n,char str1[])//開辟一個數組存放轉變后的式子,這樣方便計算結果時調用
{
int i,j=0;
char x;
SeqStack S;
StackInitiate(&S);
StackPush(&S,'#');
for(i=0;i<n;i++)
{
/*1*/ if(str[i]=='|')
{
StackTop(S,&x);
while(x!='#'&&x!='(')
{
StackPop(&S,&x);
printf("%c",x);
str1[j++]=x;
StackTop(S,&x);
}
StackPush(&S,str[i]);continue;
}
//-------------非號
if(str[i]=='!')
{
/*StackTop(S,&x);
while(x=='!')
{
StackPop(&S,&x);
printf("%c",x);
str1[j++]=x;
StackTop(S,&x);
}*/
StackPush(&S,str[i]);//當前符號入棧
continue;
}
/*3*/else if(str[i]=='(')//直接進棧,優先級最高
{
StackTop(S,&x);
StackPush(&S,str[i]);
continue;
}
/*4*/else if(str[i]=='&')
{
StackTop(S,&x);
while(x=='!'||x=='&')
{
StackPop(&S,&x);
printf("%c",x);
str1[j++]=x;
StackTop(S,&x);
}
StackPush(&S,str[i]);//當前符號入棧
continue;
}
/*5*/else if(str[i]==')')
{
//一直將當前棧頂元素出棧,直到遇到'('為止
StackTop(S,&x);
while(x!='#'&&x!='(')
{
StackPop(&S,&x);
printf("%c",x);str1[j++]=x;
StackTop(S,&x);
}
if(x=='(') StackPop(&S,&x);//若'('為將其出棧后,出棧結束而')'始終不用入棧
continue;
}
/*6*/else if(str[i]=='#')
{//將棧頂元素依次出棧,直遇到'#'出棧結束
StackTop(S,&x);
while(x!='#')
{
StackPop(&S,&x);
printf("%c",x);str1[j++]=x;
StackTop(S,&x);
}
if(x=='#') StackPop(&S,&x);//將棧內的最后一個元素出棧,表達式轉換完畢
continue;
}
/*7*/else
{
printf("%c",str[i]);str1[j++]=str[i];
continue;
}
}
printf("\n");
return j;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -