Results 1 to 2 of 2

Thread: Postfix/Prefix

  1. #1

    Thread Starter
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403

    Postfix/Prefix

    heeelp.
    I've got a test tomorrow on binary / expression trees, and I understand it all except this whole concept of writing expressions in prefix/postfix/infix. My teacher worked through changing the expression a term at a time, but I always seem to get stuck near the end...
    Code:
    6 + (5 + 1) * (3 - 2) ^ 2
    How would I express this in pre/post fix?
    Last edited by sunburnt; Mar 24th, 2003 at 08:41 PM.
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    If you know the expression tree part its all easy, traverse the tree around from the left side, and write down from left to right each node you hit for the first time to get prefix notation, and do the same but when you hit for the third time (imagine all nodes that dont have two leafs have a dummy nodes instead) you get the postfix notation.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

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



Click Here to Expand Forum to Full Width