1 / 9

Data Structure

Data Structure . MSc.IT Ali Abdul Karem Habib. Stack Applications.

halia
Download Presentation

Data Structure

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Data Structure MSc.IT Ali Abdul KaremHabib

  2. Stack Applications • 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. Arithmetic Expression • 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. Prefix, Postfix & Infix Notation • 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. Transforming Infix Expression into Prefix Expression • (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*- Transforming Infix Expression into Postfix Expression

  6. Transform PREFIX To INFIX : • +/*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 • Step2 : +((A*B)/C)D • Step3 : ((A*B)/C)+D Infix Expression

  7. Transform Postfix to Infix • 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. Example :- Infix : (7+8)-((6*3)/2)) Transformed to Postfix (78+63*2/-)

  9. Assignment -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 • ^ + 2 3 – C D • 3)Convert these POSTFIX to INFIX and PREFIX : • A B C + – • G H + I J / * • A B ^ C D + –

More Related