Results 1 to 2 of 2
  1. #1
    sfe23's Avatar
    sfe23 is offline Member
    Join Date
    Feb 2009
    Rep Power

    Default Help with Algorithm to the code!

    I really am trying to write the code. It has been almost a week that I am working on this and I am really stuck.
    I am trying to write a code that converts an infix expression into prefix. i.e. 3+4 becomes + 34. I already have the algorithm and I just simply try to convert that into the code but I need help on the part where I need to compare the current operator with the one on top of the stack as you may see in my comments!!

    Below is my code:
    Nopaste - No description

    I truly appreciate your help since this is a part of a way bigger assignment and if I don't do this part I cannot move on!
    Last edited by sfe23; 03-02-2009 at 01:28 AM. Reason: mistake

  2. #2
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Rep Power


    what kind of algorithm are you using?

    for the record, what i'd did was... reverse the string.
    so (A+B)/C becomes: C/(B+A).
    then use the shunting-yard algorithm to convert infix 2 postfix, which= CBA+/.
    then again, reverse the string, which = /+ABC
    (referring to prefix here...)
    Last edited by angryboy; 03-03-2009 at 08:38 AM.
    Get NotePad++ (free)

Similar Threads

  1. O(log n) algorithm help !!!!!!
    By itseeker87 in forum New To Java
    Replies: 8
    Last Post: 09-09-2008, 05:12 PM
  2. Help with making this algorithm better
    By RLRExtra in forum New To Java
    Replies: 6
    Last Post: 01-17-2008, 04:11 PM
  3. Help with algorithm
    By susan in forum New To Java
    Replies: 1
    Last Post: 07-13-2007, 10:26 PM
  4. Help me with this algorithm
    By Marcus in forum Advanced Java
    Replies: 3
    Last Post: 07-02-2007, 01:30 PM
  5. Help with Algorithm
    By Daniel in forum Advanced Java
    Replies: 2
    Last Post: 07-02-2007, 05:51 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