بتاريخ: 23 ديسمبر 20169 سنة comment_281084 السلام عليكم كيف تحويل infix expression الى post fix expression باستخدام جافا حيث يقول اليوز بإدخال infix expression I need a help please تقديم بلاغ
بتاريخ: 23 ديسمبر 20169 سنة comment_281086 إبحثي في google https://www.tutorialspoint.com/javaexamples/data_intopost.htm https://www.google.iq/webhp?source=search_app&gfe_rd=cr&ei=7BldWNW1J-H07gTPvLqIDw#q=infix+to+postfix+program+in+java بالتوفيق تقديم بلاغ
بتاريخ: 23 ديسمبر 20169 سنة كاتب الموضوع comment_281103 يوجود مشكلة في 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 ارجووووو الرد . تقديم بلاغ
بتاريخ: 24 ديسمبر 20169 سنة comment_281106 من أي موقع أخذت هذا الكود؟ عموماً الخطأ في هذا السطر if(ch>='a'&&ch<='z'||ch>='0'&&ch=='9') الصحيح هو if(ch>='a'&&ch<='z'||ch>='0'&&ch<='9') وبالتوفيق إن شاء الله تقديم بلاغ
بتاريخ: 24 ديسمبر 20169 سنة كاتب الموضوع comment_281113 من أي موقع أخذت هذا الكود؟ عموماً الخطأ في هذا السطر if(ch>='a'&&ch<='z'||ch>='0'&&ch=='9') الصحيح هو if(ch>='a'&&ch<='z'||ch>='0'&&ch<='9') وبالتوفيق إن شاء الله شكرا لك...بارك الله فيك تقديم بلاغ
انضم إلى المناقشة
يمكنك المشاركة الآن والتسجيل لاحقاً. إذا كان لديك حساب, سجل دخولك الآن لتقوم بالمشاركة من خلال حسابك.