分类: C/C++
2008-05-30 18:25:23
[NextPage]
Oper_Stack.pop();
}
Oper_Stack.push(Char_Temp);
break;
}
Index ++;
}
}
}
int Priority( char ch )
{
int priority; [Page]
switch( ch )
{
case ’+’ :
priority = 1;
break;
case ’-’ :
priority = 1;
break;
case ’*’ :
priority = 2;
break;
case ’/’ :
priority = 2;
break;
default :
priority = 0;
break;
}
return priority;
}
void Calculate_The_Postfix_Stack()
{
size_t size = 0;
string Buffer;
stringstream sstr;
stringstream temp;
double Value_Buffer;
double x,y;
char Oper_Buffer;
sstr.str(Postfix_Expression);
while( (sstr.str().size() - size) > 0 )
{
if(isdigit(sstr.str()[size])||isdigit(sstr.str()[size+1]))
{
sstr >> Value_Buffer;
temp << Value_Buffer;
temp >> Buffer;
size += (Buffer.size() + 1);
temp.clear();
Queue_Stack.push(Value_Buffer); [Page]
}
else
{
sstr >> Oper_Buffer;
y = Queue_Stack.top();
Queue_Stack.pop();
x = Queue_Stack.top();
Queue_Stack.pop();
switch(Oper_Buffer)
{
case ’+’:
Queue_Stack.push( x+y );
break;
case ’-’:
Queue_Stack.push( x-y );
break;
case ’*’:
Queue_Stack.push( x*y );
break;
case ’/’:
Queue_Stack.push( x/y );
break;
}
size += 2;
}
}
cout<<\"Result = \"<