用C++适配器stack
#include<iostream>
#include<stack>
#include<string>
using namespace std;
int main()
{
stack<char> sexp;
string exp;
cout<<"输入表达式"<<endl;
cin>>exp;
string::iterator iter=exp.begin();
while(iter!=exp.end())
{
if(*iter!=')')
sexp.push(*iter);
else
{
while(sexp.top()!='('&&!sexp.empty())
{
sexp.pop();
}
if(sexp.empty())
cout<<"dsdsdsdsdsd"<<endl;
else
{
sexp.pop();
sexp.push('@');
}
++iter;
}
return 0;
}
}
wangxinfeng6666_749290079 2011-5-13 23:13