The Artima Developer Community
Sponsored Link

Java Answers Forum
infix to postfix converter

4 replies on 1 page. Most recent reply: Oct 15, 2003 1:59 AM by Senthoorkumaran Punniamoorthy

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
Omar

Posts: 7
Nickname: wildheart
Registered: Oct, 2003

infix to postfix converter Posted: Oct 12, 2003 1:27 AM
Reply to this message Reply
Advertisement
hello everyone, it's me again. i got another question for you. am now reading about stacks and i've come across this prb that i seem to have difficulty in. here we go
use a stack in order to implement a translator from infix to postfix notation.
(infix notation: we understand. 5+9 and 5/8 operators + and / r written between brackets)
(postfix notation: computer understands 59 + 58/)
a compiler evaluates arithmetic expressions in postfix notation. hence they translate tbhe infix notation to postfix notation. so for example, we write (5+9)/5+2*8 and the compiler translates it to 59+5/28*+
so this is it. am supposed to write a class that converts infix to postfix.
infix is read as stringbuffer, java.util.stack is imported, watever my expressions are, they should include everything (+,-,/,*,%,^) but of course, according to priority. am sure u all know how it goes: ^,*,/,%,+,-
i even wrote the "algorithm" for this but i keep on screwing things up. here it is
*push '(' onto the stack
*Append ')' to infix(append at the end)
*For each character c in infix from left to right and while the stack isn't empty do
if c is a digit then append it to postfix
if c is '(' then push c onto the stack
if c is an operator then
while top of stack is an operator of equal or higher priority than c (Pop and append all of such expressions to postfix
push c onto stack
if c is ')' then
while top of stack is not '(' Pop operator from stack and append it to postfix
pop '(' from stack and discard it


i know, u guys will probably ban me now :d but pretty plz, i really need the help :(
thank you


Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: infix to postfix converter Posted: Oct 13, 2003 12:51 AM
Reply to this message Reply
Has this book reading has become a cover up story for posting home work now?

Which books that doesn't teach how to solve these problems, but has these problems? I would like to know the detail of such book so that I wouldn't buy it even accidentally!!!

Omar

Posts: 7
Nickname: wildheart
Registered: Oct, 2003

Re: infix to postfix converter Posted: Oct 15, 2003 1:32 AM
Reply to this message Reply
unfortunately, u'r half right
first i dont have the money to enter college. this is why am trying to learn on my own. watever it is that i can grab from the book. second, it's called DATA STRUCTURES AND ALGORITHMS IN JAVA
dude, if it were hw, i'd have said it. why waste my time and make up some story.

Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: infix to postfix converter Posted: Oct 15, 2003 1:50 AM
Reply to this message Reply
Thnak you for the name of the book and let me not buy it even if I am need of a Data Structure book :-)

Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: infix to postfix converter Posted: Oct 15, 2003 1:59 AM
Reply to this message Reply
Here is a source code you might want to check it out

http://mail.rochester.edu/~jg006k/download/csc172_proj2.zip

Flat View: This topic has 4 replies on 1 page
Topic: application-level variables in servlet on Domino Previous Topic   Next Topic Topic: Merging of XML files

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use