Page 2 of 2 FirstFirst 12
Results 21 to 23 of 23
  1. #21
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,423
    Rep Power
    25

    Default

    I thought I asked this before:
    Do you have the algorithm for doing that?
    And you gave me an algorithm for evaluating an expression.
    Do you have the alogrithm for converting an expression to a postfix string?

  2. #22
    unc123w's Avatar
    unc123w is offline Member
    Join Date
    Sep 2008
    Posts
    18
    Rep Power
    0

    Default

    If the character is an operator, it's precedence gets compared to that of the operator on top of the operator stack. If the current operator has the same or lower precedence, the operator on top of the stack must be evalutated next. Pop that operator off the operator stack along with a pair of operands from the operand stack and writing a new line in the output table. The character selected to hold the result should then be pushed onto the operand stack. Next, the current operator should be compared to the new top of the operator stack. Continue to generate output lines until the top of the operator stack has lower precedence than the current operator or until it is empty. At this point, push the current operator onto the top of the stack and examine the next character in the data string. When the end of the string is reached, pop any remaining operator along with its operand pair just described. Push the result character onto the operand stack after each table line is generated.

  3. #23
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,423
    Rep Power
    25

    Default

    At end of expression(end of the string), how is the output postfix string generated? Your description says " pop any remaining operator along with its operand pair just described."

    Now can you write the code for that algorithm?

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Illegal Arithmetic Operations?
    By Cruor in forum New To Java
    Replies: 13
    Last Post: 09-19-2008, 04:46 PM
  2. Stacks, lists...
    By little_polarbear in forum New To Java
    Replies: 7
    Last Post: 08-02-2008, 01:59 PM
  3. Stacks
    By Zosden in forum Advanced Java
    Replies: 15
    Last Post: 05-05-2008, 08:16 AM
  4. Using Stacks
    By ravian in forum New To Java
    Replies: 7
    Last Post: 11-28-2007, 09:53 AM
  5. Replies: 1
    Last Post: 08-07-2007, 07:05 AM

Posting Permissions

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