Home
Downloads
Projects
Forum
Portfolio
Contact
Ajinkya Mandhare
"The Goal is not to live forever...the goal is to create something that will"
Tuesday, 29 March 2011
Tagged under:
Infix to postfix
Infix to Postfix Conversion
Anonymous
8:15 am
No comment
Following is the java code for converting from infix to postfix:
// To convert Infix into Postfix import java.io.*; class infix2 { public static void main(String args[]) throws IOException { check obj=new check(); String str = new String(); char infix[]=new char[15]; char postfix[]=new char[15]; char stack[]=new char[15]; int len=0,i=0,j=0,top=-1,value; BufferedReader b=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter Expression ==> "); str=b.readLine(); len=str.length(); infix=str.toCharArray(); for(i=0;i<=len-1;i++) { int t=obj.isoperand(infix[i]); if(t==1) { postfix[j]=infix[i]; j++; } else if(top==-1) { top++; stack[top]=infix[i]; } else if(infix[i]==')') { while(stack[top]!='(') { postfix[j]=stack[top]; top--; j++; } top--; } else if(obj.priority(infix[i])>obj.priority(stack[top])) { top++; stack[top]=infix[i]; } else { if(obj.priority(infix[i])==obj.priority(stack[top])) { postfix[j]=stack[top]; top--; j++; } else { while(obj.priority(infix[i])
='A' && ch<='Z' )|| (ch>='a' && ch<='z')) return 1; else return 0; }//end of isoperand method int priority(char ch) { if(ch=='(') return 4; if(ch=='^' || ch=='%') return 3; if(ch=='*' || ch=='/') return 2; if(ch=='+' || ch=='-') return 1; if(ch==')') return 0; return -1; }//end of priority method }//end of class check
Kindly Bookmark and Share it:
Newer Post
Older Post
0 comments:
Post a comment
Subscribe to:
Post Comments (Atom)
Recommend us on Google!
RSS Feed
Twitter
Google Plus
Whats Hot This Week
Multi Window and Ripple Lock Screen for Samsung Galaxy S2 GT-i9100 Jelly Bean(4.1.2)
Samsung recently rolled out the JellyBean 4.1.2 update for Galaxy S2. The S2 users, including myself were eagerly awaiting this upgrade, an...
Generating a Unique Hardware Fingerprint for Software Licensing
Generating a hardware fingerprint is the most commonly sought technique to ensure security in case of softwares. There can be various met...
Print Web Page using JavaScript
Many a times, we come across situations where we have to selectively print only a certain part of a web page. When it comes to a norma...
Java code to remove redundant data / duplicate entries spread across multiple Files
The scenario here was that there are several text files, with redundant data in them. The objective was to remove the redundant data sp...
Zend Framework from Scratch Part II: MVC and Creating Zend Project
In the Part I of the 'Zend from Scratch' series, we installed Zend and configured the environment to create our first Zend pr...
Zend Framework from Scratch Part I: Install and Configure PHP Zend Framework
Zend Framework (ZF) is an open source, object-oriented, full-stack PHP framework created by Zend Technologies implemented in PHP 5 a...
Forgot Password Functionality in PHP
When you implement a Login functionality, one thing that becomes an obvious inclusion is the 'Forgot Password' functionality. ...
Secure Login Code using PHP and MySQL / Preventing SQL Injection using PHP
Many Web pages accept parameters from web users and generate SQL queries to the database. SQL Injection is a trick to inject SQL script...
Follow on FaceBook
0 comments:
Post a comment