الانتقال إلى المحتوى
View in the app

A better way to browse. Learn more.

مجموعة مستخدمي أوراكل العربية

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Convert Infix To Postfix

Featured Replies

بتاريخ:

السلام عليكم

كيف تحويل 

 infix expression   

الى 

post fix expression

باستخدام جافا 

حيث يقول اليوز بإدخال infix expression

 

I need a help please
 

 

 
بتاريخ:
  • كاتب الموضوع

يوجود مشكلة في output 



import java.io.*;
class StringStack
{
char stack1[]=new char[20];
int top;
void push(char ch)
{
top++;
stack1[top]=ch;
}
char pop()
{
char ch;
ch=stack1[top];
top--;
return ch;
}
int pre(char ch)
{
switch(ch)
{
case '-':return 1;
case '+':return 1;
case '*':return 2;
case '/':return 2;
}
return 0;
}
boolean operator(char ch)
{
if(ch=='/'||ch=='*'||ch=='+'||ch=='-')
return true;
else
return false;
}
boolean isAlpha(char ch)
{
if(ch>='a'&&ch<='z'||ch>='0'&&ch=='9')
return true;
else
return false;
}
void postfix(String str)
{
char output[]=new char[str.length()];
char ch;
int p=0,i;
for(i=0;i<str.length();i++)
{
ch=str.charAt(i);
if(ch=='(')
{
push(ch);
}
else if(isAlpha(ch))
{
output[p++]=ch;
}
else if(operator(ch))
{
if(stack1[top]==0||(pre(ch)>pre(stack1[top]))||stack1[top]=='(')
{
push(ch);
}
}
else if(pre(ch)<=pre(stack1[top]))
{
output[p++]=pop();
push(ch);
}
else if(ch=='(')
{
while((ch=pop())!='(')
{
output[p++]=ch;
}
}
}
while(top!=0)
{
output[p++]=pop();
}
for(int j=0;j<str.length();j++)
{
System.out.print(output[j]);
}
}
}
class intopost
{
public static void main(String[] args)throws Exception
{
String s;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
stack b=new stack();
System.out.println("Enter input string");
s=br.readLine();
System.out.println("Output String:");
b.postfix(s);
}
}


 
 
-infix expression 5+3*2
-The equivalent post fix is 532*+
 

لكن
output
 ظهر هكذا +*23 بدون 5 
 
 

ارجووووو الرد
.

بتاريخ:

من أي موقع أخذت هذا الكود؟

 

عموماً الخطأ في هذا السطر 

if(ch>='a'&&ch<='z'||ch>='0'&&ch=='9')

الصحيح هو 

if(ch>='a'&&ch<='z'||ch>='0'&&ch<='9')

وبالتوفيق إن شاء الله

بتاريخ:
  • كاتب الموضوع

من أي موقع أخذت هذا الكود؟

 

عموماً الخطأ في هذا السطر 

if(ch>='a'&&ch<='z'||ch>='0'&&ch=='9')
الصحيح هو 

if(ch>='a'&&ch<='z'||ch>='0'&&ch<='9')
وبالتوفيق إن شاء الله

 

 

 

 

 

شكرا لك...بارك الله فيك

بتاريخ:

العفو ..بالتوفيق إن شاء الله

  • بعد 11 شهور...
بتاريخ:

ماشاء الله مبدعة بجد يا استاذة

انضم إلى المناقشة

يمكنك المشاركة الآن والتسجيل لاحقاً. إذا كان لديك حساب, سجل دخولك الآن لتقوم بالمشاركة من خلال حسابك.

زائر
أضف رد على هذا الموضوع...

برجاء الإنتباه

بإستخدامك للموقع فأنت تتعهد بالموافقة على هذه البنود: سياسة الخصوصية

Account

Navigation

البحث

إعداد إشعارات المتصفح الفورية

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.