Palindrome-Computer Programming For Aeronautical Engineering And Sciences-Lecture Slides, Slides of Aeronautical Engineering

Prof. Balamohan Pawar delivered this lecture at Allahabad University for Aeronautical Engineering and Computer Programming course. Its main points are: Palindrome, String, Equality, Postfix, Infix, End, For, Loop, Process, Loop

Typology: Slides

2011/2012

Uploaded on 07/20/2012

savitha_48
savitha_48 ๐Ÿ‡ฎ๐Ÿ‡ณ

3

(1)

109 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
3
Palindrome
same both forward and backward
x y z a z y x
lb ub
4
Evaluating Postfix
Read from left to right:
the stack (the first number popped is the
second binary operand)
push the result back onto the stack
on top of stack is the answer
5 3 + 10 *
5 3 + 4 + 1 +
โ€ข A palindrome is a string that reads the
โ€ข Two questions:
โ€“ How do you check equality?
โ€“ When do you stop?
1. if a number is read, push it on the stack
2. if an operator is read, pop two numbers off
3. apply the operation to the numbers, and
4. when the expression is complete, the number
docsity.com
pf3
pf4

Partial preview of the text

Download Palindrome-Computer Programming For Aeronautical Engineering And Sciences-Lecture Slides and more Slides Aeronautical Engineering in PDF only on Docsity!

3

Palindrome

same both forward and backward x y z a z y x lb ub

4

Evaluating Postfix

Read from left to right:

the stack (the first number popped is the second binary operand)

push the result back onto the stack

on top of stack is the answer

5 3 + 10 *

5 3 + 4 + 1 +

  • A palindrome is a string that reads the
  • Two questions:
    • How do you check equality?
    • When do you stop?
  1. if a number is read, push it on the stack
  2. if an operator is read, pop two numbers off
  3. apply the operation to the numbers, and
  4. when the expression is complete, the number

5

Infix to Postfix

post_fix := โ€œโ€ Create(Op_Stack) for I in 1 .. Length loop If Is_Operand(expr(I)) = true then Append(post_fix, expr(I))

If Is_Operator(expr(I)) = true then Process_Next_Operator(expr(I)) end loop

6

Process_Next_Operator

Done := False loop If Is_Empty(Op_Stack) or next_op is โ€˜(โ€˜, set Done to True Elsif precedence(next_op) > precedence(top_operator) Push next_op onto Op_stack-- ensures higher precedence operators evaluated first Set Done to True Else Pop the operator_stack If operator popped is โ€˜(โ€˜ set Done to True Else Done = True

-- string post_fix has the result

push next_op onto Op_Stack

append operator popped to post_fix string exit when end loop

9

Infix to Postfix: Example

Infix Expression 3 + 5 * โ€“ 6 โ€“ 7 * (8 + 5)

Postfix Expression

      • 7 8 5 + * โ€“