nasim t
27th December 2012, 03:01 PM
سلام دوستان من یه برنامه از یه سایت گرفتم در مورد تبدیل عبارات پسوندی به پیشوندی اما وقتی می زنم توی برنامه ی turbo c++ خیلی خطا می زنه هر کاریم می کنم نمی تونم درستش کنم لطفا اگه می تونید توی اصلاح خطاهاش کمکم کنید یا اگه برنامه ی دیگه سراغ دارین بهم بدین ممنون می شم اینم برنامه:
#include <iostream.h>
#include <string.h>
#include <stdio.h>
#include <conio.h >
boo isOperator(char c)
{
if(c=='+' || c=='-' || c=='*' || c=='/' || c=='^')
return true;
else
return false;
}
int main()
{
stack<char> stk;
char postfix[30], prefix[30];
int j=0,len;
cout<<"ebarate prefix ra vared konid: ";
cin>>postfix;
len = strlen(postfix);
for(int i=len-1;i>=0;i--)
{
if(isOperator(postfix[i]))
stk.push(postfix[i]);
else
{
prefix[j++] = postfix[i];
while(!stk.empty() && stk.top()==flag)
{
stk.pop();
prefix[j++] = stk.top();
stk.pop();
}
stk.push(flag);
}
}
prefix[j] = 0;
reverse(prefix, prefix + len);
cout<<" prefix hast: "<<prefix;
return 0;
}
#include <iostream.h>
#include <string.h>
#include <stdio.h>
#include <conio.h >
boo isOperator(char c)
{
if(c=='+' || c=='-' || c=='*' || c=='/' || c=='^')
return true;
else
return false;
}
int main()
{
stack<char> stk;
char postfix[30], prefix[30];
int j=0,len;
cout<<"ebarate prefix ra vared konid: ";
cin>>postfix;
len = strlen(postfix);
for(int i=len-1;i>=0;i--)
{
if(isOperator(postfix[i]))
stk.push(postfix[i]);
else
{
prefix[j++] = postfix[i];
while(!stk.empty() && stk.top()==flag)
{
stk.pop();
prefix[j++] = stk.top();
stk.pop();
}
stk.push(flag);
}
}
prefix[j] = 0;
reverse(prefix, prefix + len);
cout<<" prefix hast: "<<prefix;
return 0;
}