資源簡介
數據結構實驗源碼。包括:帶括號的算術表達式求值+A Text Editor Imlementation+Huffman編碼+拓撲排序------打印輸出計算機本科專業4年每學期的課表
代碼片段和文件信息
#include?
#include?
#include?
#include?
using?namespace?std;
string?transform(string?str)//將中綴表達式轉換為后綴表達式
{
stack?ope;
int?i;
string?exp=““;
for(i=0;i {
if(str[i]==‘.‘||isdigit(str[i]))
{
exp+=str[i];
}
else?if(str[i]==‘+‘||str[i]==‘-‘)
{
int?j=i-1;
if(isdigit(str[j]))
{
exp+=“?“;//每個數字的后面都加一個空格加以區分
if(ope.empty()||ope.top()==‘(‘)
{
ope.push(str[i]);
}
else
{
while(!ope.empty()&&ope.top()!=‘(‘)
{
exp+=ope.top();
ope.pop();
}
ope.push(str[i]);
}
}
else
{
if(ope.empty()||ope.top()==‘(‘)
{
ope.push(str[i]);
}
else
{
while(!ope.empty()&&ope.top()!=‘(‘)
{
exp+=ope.top();
ope.pop();
}
ope.push(str[i]);
}
}
}
else?if(str[i]==‘*‘||str[i]==‘/‘||str[i]==‘%‘)
{???
int?j=i-1;
if(isdigit(str[j]))
{
exp+=“?“;
if(ope.empty()||ope.top()==‘(‘||ope.top()==‘+‘||ope.top()==‘-‘)
????{
ope.push(str[i]);
????}
????else
????{
?????while(!ope.empty()&&ope.top()!=‘(‘&&ope.top()!=‘+‘&&ope.top()!=‘-‘)
????{
exp+=ope.top();
ope.pop();
????}
ope.push(str[i]);
????}
}
else
{
if(ope.empty()||ope.top()==‘(‘||ope.top()==‘+‘||ope.top()==‘-‘)
{
ope.push(str[i]);
}
else
{
while(!ope.empty()&&ope.top()!=‘(‘&&ope.top()!=‘+‘&&ope.top()!=‘-‘)
{
exp+=ope.top();
ope.pop();
}
ope.push(str[i]);
}
}
}
//}
else?if(str[i]==‘^‘)
{
int?j=i-1;
if(str[j]!=‘)‘)
{
exp+=“?“;
}
ope.push(str[i]);
}
else?if(str[i]==‘(‘)
{
ope.push(str[i]);
}
else?if(str[i]==‘)‘)
{
exp+=“?“;
while(ope.top()!=‘(‘)
{
exp+=ope.top();
ope.pop();
}
ope.pop();
}
else
{
return?“有錯誤“;
}
}
while(!ope.empty())//遍歷完表達式將堆棧中的所有運算符輸出
{??
if(isdigit(exp[exp.length()-1]))
{
exp=exp+“?“+ope.top();
????ope.pop();
}
????else
{?
exp=exp+ope.top();
????ope.pop();
}
}
return?exp;
}
int?examine(string?str)//檢查輸入的表達式是否有誤
{
if((isdigit(str[str.length()-1])!=0||str[str.length()-1]==‘)‘)&&(isdigit(str[0])!=0||str[0]==‘+‘||str[0]==‘-‘||str[0]==‘(‘))
{
int?i;
for(i=0;i {
if(str[i]==‘/‘||str[i]==‘%‘||str[i]==‘*‘||str[i]==‘^‘)
{???
int?a=i+1;
????if(str[a]==‘/‘||str[a]==‘*‘||str[a]==‘%‘||str[a]==‘)‘||str[a]==‘.‘)
{
cout<<“表達式有錯誤“< ????return?1;
????break;
}
}
else?if(str[i]==‘+‘||str[i]==‘-‘)
{
int?a=i+1;
if(str[a]==‘/‘||str[a]==‘*‘||str[a]==‘%‘||str[a]==‘)‘||str[a]==‘.‘||str[a]==‘^‘)
{cout<<“表達式有錯誤“< return?1;
break;}
}
else?if(isdigit(str[i])!=0)
{
int?a=i+1;
if(str[a]==‘(‘)
{
cout<<“表達式有錯誤“< return?1;
break;
}
}
else?if(isdigit(st
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2019-09-03?19:40??實驗\
?????目錄???????????0??2019-09-03?19:31??實驗\Calculator\
?????文件????????5049??2018-12-17?09:40??實驗\Calculator\main.cpp
?????文件?????2038891??2019-09-03?19:30??實驗\Calculator\main.exe
?????目錄???????????0??2019-09-03?19:33??實驗\classtime
?????文件???????10126??2018-12-19?23:50??實驗\classtime
?????文件?????1977882??2019-09-03?19:33??實驗\classtime
?????文件?????????644??2012-12-11?14:35??實驗\classtime
?????目錄???????????0??2019-09-03?19:39??實驗\editor\
?????目錄???????????0??2019-09-03?19:39??實驗\editor\Debug\
?????文件???????11982??2018-12-12?16:12??實驗\editor\Debug\CL.read.1.tlog
?????文件?????????252??2018-12-12?16:12??實驗\editor\Debug\CL.write.1.tlog
?????文件?????????632??2018-12-12?16:12??實驗\editor\Debug\cl.command.1.tlog
?????文件??????701952??2018-12-14?22:09??實驗\editor\Debug\editor.exe
?????文件?????????406??2018-12-12?16:12??實驗\editor\Debug\editor.exe.em
?????文件?????????472??2018-12-12?16:12??實驗\editor\Debug\editor.exe.em
?????文件?????????381??2018-12-14?22:09??實驗\editor\Debug\editor.exe.intermediate.manifest
?????文件?????1739408??2018-12-14?22:09??實驗\editor\Debug\editor.ilk
?????文件??????????76??2018-12-14?22:09??實驗\editor\Debug\editor.lastbuildstate
?????文件????????1988??2018-12-14?22:09??實驗\editor\Debug\editor.log
?????文件?????2927616??2018-12-14?22:09??實驗\editor\Debug\editor.pdb
?????文件?????????713??2018-12-12?16:12??實驗\editor\Debug\editor.vcxprojResolveAssemblyReference.cache
?????文件???????????0??2018-12-12?16:12??實驗\editor\Debug\editor.write.1.tlog
?????文件?????????208??2018-12-12?16:12??實驗\editor\Debug\editor_manifest.rc
?????文件???????????0??2018-12-17?14:17??實驗\editor\Debug\file_out.txt
?????文件???????????2??2018-12-14?22:09??實驗\editor\Debug\li
?????文件???????????2??2018-12-14?22:09??實驗\editor\Debug\li
?????文件???????????2??2018-12-14?22:09??實驗\editor\Debug\li
?????文件???????????2??2018-12-14?22:09??實驗\editor\Debug\li
?????文件???????????2??2018-12-14?22:09??實驗\editor\Debug\li
?????文件???????????2??2018-12-14?22:09??實驗\editor\Debug\li
............此處省略97個文件信息
評論
共有 條評論