Presentation is loading. Please wait.

Presentation is loading. Please wait.

D ATA S TRUCTURE MSc.IT Ali Abdul Karem Habib. S TACK A PPLICATIONS Web browser: stores the addresses of recently visited sites on a stack. Each time.

Similar presentations


Presentation on theme: "D ATA S TRUCTURE MSc.IT Ali Abdul Karem Habib. S TACK A PPLICATIONS Web browser: stores the addresses of recently visited sites on a stack. Each time."— Presentation transcript:

1 D ATA S TRUCTURE MSc.IT Ali Abdul Karem Habib

2 S TACK A PPLICATIONS Web browser: stores the addresses of recently visited sites on a stack. Each time a user visits a new site, the address of the site is pushed into the stack of addresses. Use the back button the user can pop pack to previously visited sites!. Text editors: powerful text editors keep text changes in a stack. The user can use the undo mechanism to cancel recent editing operations.

3 A RITHMETIC E XPRESSION An arithmetic expression is one which is evaluated by performing a sequence of arithmetic operations to obtain a numeric value. Levels of Precedence for the usual five binary operations on arithmetic operation Q. Highest: Exponentiation (^) Next Highest: Multiplication (*)and division (/) Lowest: Addition (+) and subtraction (-)

4 P REFIX, P OSTFIX & I NFIX N OTATION Infix : the operator is placed between operands. Example: (A+B)*C parentheses necessary Prefix: the operator is placed before the operands Example: *+ABC Postfix ( Reveres polish notation) : the operator is placed after the operands. Example: AB+C*

5 T RANSFORMING I NFIX E XPRESSION INTO P REFIX E XPRESSION (A+B) – (C*D) Step 1 : +AB Step2 : *CD +AB-*CB Prefix :- -+AB*CB  (A+B) – (C*D)  Step 1 : AB+  Step 2 : CD* AB+-CD* Postfix : AB+CD*- T RANSFORMING I NFIX E XPRESSION INTO P OSTFIX E XPRESSION

6 +/*A B C D Note : We will Start the tack operator from the right and the operands from the left. Step 1 : First 2 Operands from the left and first operator from the right. +/(A*B)CD o Step2 : +((A*B)/C)D o Step3 : ((A*B)/C)+D Infix Expression T RANSFORM PREFIX T O INFIX :

7 T RANSFORM P OSTFIX TO I NFIX A B C + – Note :- We will tack the operator from the left and 2 operands from the left also. Step 1 : (A+B)C- Step2 : (A+B)- C

8 E XAMPLE :- I NFIX : (7+8)-((6*3)/2)) T RANSFORMED TO P OSTFIX (78+63*2/-) StepsInputStack Pop ( 8 and 7 ) push result * Pop ( 6 and 3 ) push result / pop ( 18 2 ) push result Pop ( 15 and 9 ) push result 6 Final Result in Stack

9 A SSIGNMENT -4- 1)Convert these INFIX to PREFIX and POSTFIX : A / B – C / D (A + B) ^ 3 – C * D A ^ (B + C) 2)Convert these PREFIX to INFIX and POSTFIX : + – / A B C ^ D E – + D E / X Y ^ – C D 3)Convert these POSTFIX to INFIX and PREFIX : A B C + – G H + I J / * A B ^ C D + –


Download ppt "D ATA S TRUCTURE MSc.IT Ali Abdul Karem Habib. S TACK A PPLICATIONS Web browser: stores the addresses of recently visited sites on a stack. Each time."

Similar presentations


Ads by Google