91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 674KB
    文件類型: .rar
    金幣: 2
    下載: 0 次
    發布日期: 2021-05-08
  • 語言: 其他
  • 標簽: 計算器??語法樹??

資源簡介

實現了中綴式變后綴,語法樹的生成,可以進行簡單的計算

資源截圖

代碼片段和文件信息

#include“seqstack.h“
#include“Function.h“
#?include
char?string[30];??//從鍵盤接受的源字符串組
char?postex[30];????//轉化后的后綴式數組
char?tree[10][3];???//存放語法樹
Function?f;
seqstack?stack(30);
void?print(char?s[]int?l)
{

for(int?i=0;i {
if(s[i]==‘#‘)?break;
else?cout< }
cout<}

//把中綴式變為后綴式,形參是中綴表達式?
void?postfix(char?s[])??
{
int?ij;
stack.push(‘#‘);
char?x1=stack.gettop();
i=j=0;
char?x2=s[i++];
while(!stack.empty())
{
//數字與字母直接輸出
if(f.characterType(x2)==0)
{
postex[j++]=x2;
x2=s[i++];
}
else?if(f.characterType(x2)==1)
{
postex[j++]=x2;
x2=s[i++];
}
//進行運算符(op1op2)優先級的比較
else?if(f.priority_comp(x1x2)==‘<‘)
{
stack.push(x2);
x1=stack.gettop();
x2=s[i++];
}
else?if(f.priority_comp(x1x2)==‘>‘)
{
x1=stack.pop();
postex[j++]=x1;
if(!stack.empty())
x1=stack.gettop();
}
else?if(f.priority_comp(x1x2)==‘=‘)
{
if(x2==‘#‘||x2==‘=‘)?break;
else?{
stack.pop();
if(!stack.empty())
{
x1=stack.gettop();
x2=s[i++];
}
}
}
}
//增加一個結束標志
postex[j++]=‘#‘;
stack.clear();

}
//輸出語法樹
void?printtree(char?s[])
{
//本程序只實現了簡單的四則運算
char?oparray[4]={‘+‘‘-‘‘*‘‘/‘};
int?l=(int)strlen(s);
int?ij;
int?m=0;
int?t=-1;
int?p=0;
char?sa;
for(i=0;i {
sa=s[i];

if(sa==‘#‘)?break;//如果為‘#’,結束
//找到后綴式中的第一個運算符
for(j=0;j<4;j++)
{
while(sa!=oparray[j])?j++;?
if(j<4)?break;
}
if(j<4)
{
p=i-1;
tree[m][0]=sa;
s[i]=‘#‘;
if(s[p]!=‘#‘)
{
tree[m][2]=s[p];
s[p]=‘#‘;
if(s[p-1]!=‘#‘)
{
tree[m][1]=s[p-1];
s[p-1]=‘#‘;
if(m!=0)?t=m-1;

}
else?tree[m][1]=char(m-1);
}
else
{
p--;
while(p>=0&&s[p]==‘#‘)?p--;
if(p>=0)
{
tree[m][1]=s[p]s[p]=‘#‘;
tree[m][2]=char(m-1);

}
else
{
tree[m][1]=char(t);
tree[m][2]=char(m-1);

}
}
m++;
}
}
m--;
int?left=19center=20;
//可以輸出??‘/‘?或者?‘\‘作為指示!!
for(?;m>=0;m--)??????????????
{
if(tree[m][0]!=‘L‘&&tree[m][0]!=‘R‘)
cout< else?if(tree[m][0]==‘L‘)?left=center-6center=left;
else?left=center+3center=left;
if(f.characterType(tree[m][1])==0)?
left-=3cout< else
{
t=int(tree[m][1]);
left-=3;
cout< tree[t][0]=‘L‘;
}
if(f.characterType(tree[m][2])==0)
cout< else
{
t=int(tree[m][2]);
cout< tree[t][0]=‘R‘;
}
cout< }
stack.clear();
}




//計算表達式的結果,利用全局變量oparg等
double?compute(char?s[])
{

stack.push(‘#‘);
int?l=(int)strlen(s);
int?ij;
//先判斷表達式是否能計算,是否存在異常!
for(i=0;i if(f.characterType(s[i])==0)
{
cout<<“?表達式中有符號變量需要賦值,無法求出結果!!“<

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件?????379392??2008-05-19?11:10??編譯實驗\報告.doc

?????文件???????4899??2008-05-19?11:08??編譯實驗\代碼\ff.cpp

?????文件??????50176??2002-07-02?15:24??編譯實驗\代碼\ff.ncb

?????文件????????238??2002-07-02?15:24??編譯實驗\代碼\ff.plg

?????文件???????1676??2008-05-18?22:11??編譯實驗\代碼\Function.h

?????文件???????1186??2008-05-18?21:27??編譯實驗\代碼\seqstack.h

????..A.SH.?????22016??2008-05-19?10:51??編譯實驗\代碼\Thumbs.db

?????文件???????3693??2002-07-02?15:24??編譯實驗\代碼\ff.dsp

?????文件??????48640??2002-07-02?15:24??編譯實驗\代碼\ff.opt

?????文件????????529??2002-07-02?15:24??編譯實驗\代碼\ff.dsw

?????文件?????241718??2008-05-19?11:08??編譯實驗\代碼\Debug\ff.exe

?????文件?????488252??2008-05-19?11:08??編譯實驗\代碼\Debug\ff.ilk

?????文件??????33168??2008-05-19?11:08??編譯實驗\代碼\Debug\ff.obj

?????文件?????300044??2008-05-18?22:11??編譯實驗\代碼\Debug\ff.pch

?????文件?????574464??2008-05-19?11:08??編譯實驗\代碼\Debug\ff.pdb

?????文件??????58368??2002-07-02?15:24??編譯實驗\代碼\Debug\vc60.idb

?????文件??????69632??2008-05-19?11:08??編譯實驗\代碼\Debug\vc60.pdb

?????目錄??????????0??2002-07-02?15:25??編譯實驗\代碼\Debug

?????目錄??????????0??2002-07-02?15:25??編譯實驗\代碼

?????目錄??????????0??2002-07-02?15:24??編譯實驗

-----------?---------??----------?-----??----

??????????????2278091????????????????????20


評論

共有 條評論