Click here to Skip to main content
15,895,875 members
Home / Discussions / Java
   

Java

 
AnswerRe: what does this mean? Pin
TorstenH.30-Jan-11 20:53
TorstenH.30-Jan-11 20:53 
GeneralRe: what does this mean? Pin
pancakeleh30-Jan-11 21:04
pancakeleh30-Jan-11 21:04 
AnswerRe: what does this mean? Pin
Richard MacCutchan30-Jan-11 22:48
mveRichard MacCutchan30-Jan-11 22:48 
GeneralRe: what does this mean? [modified] Pin
pancakeleh31-Jan-11 14:10
pancakeleh31-Jan-11 14:10 
GeneralRe: what does this mean? Pin
Cedric Moonen31-Jan-11 20:23
Cedric Moonen31-Jan-11 20:23 
GeneralRe: what does this mean? Pin
Richard MacCutchan31-Jan-11 22:07
mveRichard MacCutchan31-Jan-11 22:07 
AnswerRe: what does this mean? Pin
bhavitk15-Feb-11 4:06
bhavitk15-Feb-11 4:06 
Questionerror in infix to postfix conversion [modified] Pin
WindowsVsLinux28-Jan-11 3:01
WindowsVsLinux28-Jan-11 3:01 
Hi,
i have developed a Java program to convert an infix expression into a postfix expression but in output i am getting null. Below is my program . There is some conceptual mistake but i am unable to find it out. please help me...

import java.util.Stack;
public class infixToPostfix{
    private int index;
    private char ch;
    private char lparenthesis='(';
    private char rparenthesis=')';
    Stack stack=new Stack();
    private String output="";
    public boolean isOperator(char op){
        if(op == '^' || op == '*' ||op == '/' || op == '%' || op == '+' || op == '-')return true;
        else return false;
    }
    public boolean isOperand(char opr){
        if(opr >= 'A' && opr <='Z')return true;
        else if(opr >= 'a' && opr <= 'z')return true;
        else return false;
    }
    public int getPrecedence(char c){
        switch(c){
            case '(': case ')': return 5;
            case '^':return 4;
            case '*': case '/': case '%': return 3;
            case '+': case '-': return 2;
        }return 0;
    }
    public String getPostfix(String expr){      
        stack.push('(');
        for(index=0;index<expr.length();index++){
            ch=expr.charAt(index);                      
            if(isOperand(ch)){
                output=output+ch;
            }
            else if(ch == lparenthesis){
                stack.push(lparenthesis);
            }
            else if(isOperator(ch)){
               Object pop=stack.pop();
               char ch1=pop.toString().charAt(0);
               while(getPrecedence(ch1) >= getPrecedence(ch) ){
                   if(!stack.empty())stack.pop();
                   else break;
                   if(isOperator(ch1)){
                       output=output+ch1;
                   }
               }stack.push(ch);
            }
            else if(ch == rparenthesis){
                while(stack.pop().toString().charAt(0) != lparenthesis){
                    if(isOperator(stack.pop().toString().charAt(0)))
                    output=output+stack.pop();
                }                
            }
            else {
               System.out.print("error.");
            }
        }
        stack.clear();
        return output;
    }
}


modified on Saturday, January 29, 2011 1:19 AM

AnswerRe: error in infix to postfix conversion Pin
Richard MacCutchan28-Jan-11 3:30
mveRichard MacCutchan28-Jan-11 3:30 
GeneralRe: error in infix to postfix conversion Pin
WindowsVsLinux28-Jan-11 19:30
WindowsVsLinux28-Jan-11 19:30 
GeneralRe: error in infix to postfix conversion Pin
Richard MacCutchan28-Jan-11 21:18
mveRichard MacCutchan28-Jan-11 21:18 
AnswerRe: error in infix to postfix conversion Pin
jschell29-Jan-11 10:39
jschell29-Jan-11 10:39 
GeneralRe: error in infix to postfix conversion Pin
WindowsVsLinux30-Jan-11 5:36
WindowsVsLinux30-Jan-11 5:36 
GeneralRe: error in infix to postfix conversion Pin
jschell30-Jan-11 9:46
jschell30-Jan-11 9:46 
QuestionPDF Annotator Pin
Civic0627-Jan-11 15:23
Civic0627-Jan-11 15:23 
AnswerRe: PDF Annotator Pin
David Skelly27-Jan-11 22:30
David Skelly27-Jan-11 22:30 
GeneralRe: PDF Annotator Pin
Civic0627-Jan-11 23:07
Civic0627-Jan-11 23:07 
GeneralRe: PDF Annotator Pin
Richard MacCutchan28-Jan-11 1:37
mveRichard MacCutchan28-Jan-11 1:37 
GeneralRe: PDF Annotator Pin
David Skelly28-Jan-11 2:09
David Skelly28-Jan-11 2:09 
QuestionChanging the CSS properties of a menu bar. Pin
Douglas Kirk24-Jan-11 20:42
Douglas Kirk24-Jan-11 20:42 
AnswerRe: Changing the CSS properties of a menu bar. Pin
Richard MacCutchan24-Jan-11 21:25
mveRichard MacCutchan24-Jan-11 21:25 
GeneralRe: Changing the CSS properties of a menu bar. Pin
Douglas Kirk24-Jan-11 21:38
Douglas Kirk24-Jan-11 21:38 
Question.properties file added to database Pin
pancakeleh23-Jan-11 17:07
pancakeleh23-Jan-11 17:07 
AnswerRe: .properties file added to database Pin
David Skelly23-Jan-11 22:18
David Skelly23-Jan-11 22:18 
GeneralRe: .properties file added to database [modified] Pin
pancakeleh24-Jan-11 15:46
pancakeleh24-Jan-11 15:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.