Results 1 to 2 of 2

Thread: stack Java help

  1. #1
    judemartin99 is offline Member
    Join Date
    Feb 2013
    Posts
    12
    Rep Power
    0

    Default stack Java help

    How can a stack be used to solve the following postfix expression:
    3 4 * 15 2 4 / - +
    Describe the rules to be followed as each character is read.

    I don't understand what the problem is asking me to do. Can someone help me please understand and at least give me an idea on how to start
    it,

    thanks for the help

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,382
    Rep Power
    5

    Default Re: stack Java help

    Postfix notation (also known as Reverse Polish Notation) works as follows. Keep pushing elements on the stack. When you get an operator, pop two elements off the stack and apply the operator. Push the result back on the stack. Continue the process until no more tokens. At the end, the top element should be the result.

    e.g.

    4 5 3 - * would be evaluated as follows:

    4 5 3 -
    4 2 *
    8

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. Replies: 2
    Last Post: 01-14-2012, 08:56 PM
  2. java stack RPN calculator
    By ali1 in forum New To Java
    Replies: 0
    Last Post: 10-30-2011, 09:04 PM
  3. Java Stack and Queue
    By jeanjiang in forum New To Java
    Replies: 3
    Last Post: 04-25-2011, 02:19 PM
  4. Java Stack Overflow?
    By fullmetaljacket in forum New To Java
    Replies: 0
    Last Post: 05-19-2009, 07:49 PM
  5. Using java.util.Stack
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-20-2007, 05:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •