Jump to content

Question(Data Structures)

PugoOfficial

Can someone tell me what is hierarchy of operators (in infix,prefix,postfix notations)

CPU: Intel Core i7-4790K @ 4.0GHz | COOLING: Corsair H100i Liquid Cooler | MOTHERBOARD: ASUS Maximus VII Formula ATX | MEMORY: Corsair Vengeance Pro Series 16GB (2 x 8) DDR3-1866 | STORAGE: Intel 730 Series 480GB SSD + Seagate Barracuda 3TB HDD | PSU: Corsair AX860i 80+ Platinum | GPU: ASUS GeForce GTX 780Ti DirectCU II (2-Way SLI) | CASE: Phanteks Enthoo Luxe (Black) | DISPLAY: ASUS PB278Q 27.0" (2560 x 1440) | KEYBOARD: Razer BlackWidow Chroma | MOUSE: Razer Deathadder Chroma | SOUND: Logitech Z906 5.1 Speakers / Razer Kraken Chroma | OS: Microsoft Windows 8.1 (64-bit)

Link to comment
Share on other sites

Link to post
Share on other sites

For infix notation, (eg. (1 + 1) * 2)

It follows the standard "BEDMAS" (although that is technically not correct either), but keeping it simple it is: Brackets, Exponents, Division, Multiplication, Addition, and then Subtraction. If you wanted to explicitly apply the order of operations, you would need to wrap brackets as opposed to the other two notations.

 

 

For prefix notation, also known as Polish Notation, (eg. * + 1 1 2)

It is like a stack of operations, from inside out. In essence it is in this format: <operator> <value1> <value2>

Where each value can be another polish notation expression.

 

For example: * + 1 1 2

= * (+ 1 1) (2)

= * (2) (2)

= 4

 

Note: (the parenthesis are not required, just easier to visually see what is going on)

 

This can seem very confusing if not use to the notation, but advantage is it leave very little ambiguity of which operation applies first, and thus does not require any parenthesis.

 

 

For postfix notation, also known as Reverse Polish Notation, (eg. 1 1 + 2 *)

As the name suggests, it is the opposite of Polish Notation where the operator goes after the two values instead of before.

 

 

Edited by KuroSetsuna29
Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×