PDA

View Full Version : Help For Stack And Suffrix



eyes_shut_number1
شنبه 05 خرداد 1386, 11:39 صبح
سلام خوبید؟ یک سوال داشتم.میخواستم با استفاده از پشته عبارتهای میان وندی رو به پس وندی تبدیل کنم.یه چیزایی نوشتم.شاید اطلاعاتم کافی نیسا شگه ممکن اونو اصلاحش کنید و برام بذارید.اخه خیلی مهمه.ممنون
*Exp : 2+3*4 (With Stack) --->23+4

/*araye PISHVANDI kafi ast ke shomaresh az akhar be aval bashad va bejaye a>prv in ebarat ra jaygozin koni, --? a>= prv */
#include<iostream.h>
#include<conio.h>
void push (char x,int a);
int pop (int x);
int Char (char x);
char stack[1000];
int top=-1;
int result;
int main ()
{
cout<<"Lotfan Ebarate Khod Ra VaRed Konid"<<endl;
cout<<"---------------------------------------------"<<endl;
char n[10];
int i=0;
for (i=0;i<10;i++)
{
cout<<i<<" - Action : ";
cin>>n[i];
}
for (i=0 ; i<10 ; i++)
{
result=Char (n[i]);
if (result== -1)
cout<<n[i];
else
push(n[i],result);
}
pop(result);
return 0;
}
void push (char x,int a)
{
int prv;
if (!top==999)
{
prv=Char(stack[top]);
if (top==-1 || a>prv)
{
top++;
stack[top]=x;
}
else
{
while (prv<a || top==-1)
pop(prv);
top++;
stack[top]=x;
}
}
cout<<"Stack Is Full";
}
int pop (int x)
{
if (!top==-1)
{
if(x==4)
while (x!=3)
{
{
cout<< stack[top--];
return 0;
}
else
{
cout<< stack[top--];
return 0;
}
}
}
else cout<<" ---> Stack Is Empty";
return 0;
}
int Char (char x)
{
if (x=='+' || x=='-') return 0;
else if (x=='*' || x=='/') return 1;
else if (x=='^') return 2;
else if (x=='(') return 3;
else if (x==')') return 4;
else if (x=='1' || x=='2' || x=='3' || x=='4' || x=='5' || x=='6' || x=='7' || x=='8' || x=='9' || x=='0') return -1;
else return -2;
}

SeyyedKarim
دوشنبه 07 خرداد 1386, 14:21 عصر
بنام خدا
برنامه تبدیل عبارات میانوندی به پسوندی را ضمیمه کردم(با Borland C++ V5 اجرا میشه)البته این دقیقا چیزی که خواسته شده نیست ، شاید بدردت بخوره

eyes_shut_number1
دوشنبه 07 خرداد 1386, 19:51 عصر
مرسی:بوس: :خجالت: