SlideShare a Scribd company logo
2
Most read
3
Most read
4
Most read
DATA STRUCTURES
ASSIGNMENT # 2
“Infix to Prefix Conversion, Evaluation and Pseudo code”
SUBMITTED TO:
Zaheer Sani
SUBMITTED BY:
Ahmed Khateeb
SP12-BCS-028
BSCS – IIIC
Department of Computer Science
A) CONVERSION INFIX EXPRESSION TO PREFIX.
B) EVALUATION OF INFIX EXPRESSION (AND VERIFICATION).
C) PSEUDO CODE TO CONVERT INFIX TO PREFIX
PART A
- Let have an Infix Expression
( (A+B) * (C+D) / (E-F) ) + G
- Reading Expression from “right to left” character by
character.
- We have Input, Prefix_Stack & Stack.
- Now converting this expression to Prefix.
Input Prefix_Stack Stack
G G (empty)
+ G +
) G + )
) G + ) )
F GF + ) )
- GF + ) ) -
E GFE + ) ) -
( GFE- + )
/ GFE- + ) /
) GFE- + ) / )
D GFE-D + ) / )
+ GFE-D + ) / ) +
C GFE-DC + ) / ) +
( GFE-DC+ + ) /
* GFE-DC+ + ) / *
) GFE-DC+ + ) / * )
B GFE-DC+B + ) / * )
+ GFE-DC+B + ) / * ) +
A GFE-DC+BA + ) / * ) +
( GFE-DC+BA+ + ) / *
( GFE-DC+BA+*/ +
(empty) GFE-DC+BA+*/+ (empty)
- Now pop-out Prefix_Stack to output (or simply reverse).
Prefix expression is
+ / * + A B + C D – E F G
PART B
- First I’m assigning values to all operands.
A = 14
B = 12
C = 10
D = 8
E = 6
F = 4
G = 2
- Evaluating Infix expression using above values.
( (14+12) * (10+8) / (6-4) ) + 2
( 26 * 18 / 2 ) + 2
( 468 / 2 ) + 2
( 234 ) + 2
236
- Evaluating Infix expression using above values.
+ / * + 14 12 + 10 8 - 6 4 2 (14+2 & 10+8 & 6-4)
+ / * 26 18 2 2 (26 * 18)
+ / 468 2 2 (468 / 2)
+ 234 2 (234 + 2)
236
- Both are same, so our conversion is correct!
PART C
Arr = (Infix Expression)
Set loop_counter to length_ of_ Arr
do
character = arr[loop_counter]
if character is operator
push character to prefix_stack
if character is ‘)’
push character to stack
if character is ‘(’
do
pop character and push it to prefix_stack
until character equals ‘(‘
if character is operator
if character_precedence is greater OR is equal to stack[top]_ precedence
push to stack
else
do
pop from stack and push to prefix_stack
until condition satisfices
loop_counter = loop_counter - 1
While loop_counter IS NOT EQUAL to 0
Pop out prefix_stack and display each element

More Related Content

PPTX
Pointer in c
PPTX
Conversion of Infix to Prefix and Postfix with Stack
PPT
Infix prefix postfix
DOCX
Conversion from infix to prefix using stack
PPT
RECURSION IN C
PPTX
Circular link list.ppt
PPTX
Pointers in C Programming
PPTX
Types of Constructor in C++
Pointer in c
Conversion of Infix to Prefix and Postfix with Stack
Infix prefix postfix
Conversion from infix to prefix using stack
RECURSION IN C
Circular link list.ppt
Pointers in C Programming
Types of Constructor in C++

What's hot (20)

PPTX
Multiplication algorithm
PPTX
Linked list
PPTX
Stack - Data Structure - Notes
PPTX
Structure in C
DOC
Infix to-postfix examples
PDF
Sop and pos
PPTX
STACKS IN DATASTRUCTURE
PPT
PPTX
Signed Addition And Subtraction
PPTX
Function overloading
PPT
Chapter 5 Syntax Directed Translation
PPTX
Infix to postfix conversion
PPT
Expression evaluation
PDF
Shift micro operations & 4 bit combinational circuit shifter
PPT
Function overloading(c++)
ODP
Python Modules
PPSX
INTRODUCTION TO C PROGRAMMING
PPSX
PPTX
sorting and its types
PDF
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
Multiplication algorithm
Linked list
Stack - Data Structure - Notes
Structure in C
Infix to-postfix examples
Sop and pos
STACKS IN DATASTRUCTURE
Signed Addition And Subtraction
Function overloading
Chapter 5 Syntax Directed Translation
Infix to postfix conversion
Expression evaluation
Shift micro operations & 4 bit combinational circuit shifter
Function overloading(c++)
Python Modules
INTRODUCTION TO C PROGRAMMING
sorting and its types
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
Ad

Similar to Infix to Prefix (Conversion, Evaluation, Code) (20)

PPTX
Prefix, Infix and Post-fix Notations
PPTX
week9-prefixinfixandpostfixnotations-191013065821.pptx
PDF
1.3- infix-ti-postfix.pdf
PPTX
My lecture infix-to-postfix
PPT
Infix to Postfix Conversion Using Stack
PPTX
STACK APPLICATIONS: INFOX TO POSTFIX CONVERSION AND EVALUATION OF POSTFIX EXP...
PPT
data structure and algorithm by bomboat_3
PPT
Application of Stacks
PPTX
2.2 stack applications Infix to Postfix & Evaluation of Post Fix
PPT
MO 2020 DS Stacks 3 AB.ppt
PPTX
Infix-Postfix expression conversion
PDF
The concept of stack is extremely important in computer science and .pdf
PPTX
Data Structures and Agorithm: DS 08 Infix to Postfix.pptx
PPTX
Unit 2 application of stack
PDF
Applications of Stack
PPTX
conversion of Infix to Postfix conversion using stack
PPTX
Topic 2_revised.pptx
PPT
Computer notes - Postfix
PPT
computer notes - Data Structures - 7
Prefix, Infix and Post-fix Notations
week9-prefixinfixandpostfixnotations-191013065821.pptx
1.3- infix-ti-postfix.pdf
My lecture infix-to-postfix
Infix to Postfix Conversion Using Stack
STACK APPLICATIONS: INFOX TO POSTFIX CONVERSION AND EVALUATION OF POSTFIX EXP...
data structure and algorithm by bomboat_3
Application of Stacks
2.2 stack applications Infix to Postfix & Evaluation of Post Fix
MO 2020 DS Stacks 3 AB.ppt
Infix-Postfix expression conversion
The concept of stack is extremely important in computer science and .pdf
Data Structures and Agorithm: DS 08 Infix to Postfix.pptx
Unit 2 application of stack
Applications of Stack
conversion of Infix to Postfix conversion using stack
Topic 2_revised.pptx
Computer notes - Postfix
computer notes - Data Structures - 7
Ad

Recently uploaded (20)

PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Business Ethics Teaching Materials for college
PDF
Basic Mud Logging Guide for educational purpose
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Pre independence Education in Inndia.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Institutional Correction lecture only . . .
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
FourierSeries-QuestionsWithAnswers(Part-A).pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
O5-L3 Freight Transport Ops (International) V1.pdf
PPH.pptx obstetrics and gynecology in nursing
Business Ethics Teaching Materials for college
Basic Mud Logging Guide for educational purpose
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
Pre independence Education in Inndia.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Anesthesia in Laparoscopic Surgery in India
Institutional Correction lecture only . . .
Microbial disease of the cardiovascular and lymphatic systems
human mycosis Human fungal infections are called human mycosis..pptx
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table

Infix to Prefix (Conversion, Evaluation, Code)

  • 1. DATA STRUCTURES ASSIGNMENT # 2 “Infix to Prefix Conversion, Evaluation and Pseudo code” SUBMITTED TO: Zaheer Sani SUBMITTED BY: Ahmed Khateeb SP12-BCS-028 BSCS – IIIC Department of Computer Science
  • 2. A) CONVERSION INFIX EXPRESSION TO PREFIX. B) EVALUATION OF INFIX EXPRESSION (AND VERIFICATION). C) PSEUDO CODE TO CONVERT INFIX TO PREFIX PART A - Let have an Infix Expression ( (A+B) * (C+D) / (E-F) ) + G - Reading Expression from “right to left” character by character. - We have Input, Prefix_Stack & Stack. - Now converting this expression to Prefix. Input Prefix_Stack Stack G G (empty) + G + ) G + ) ) G + ) ) F GF + ) ) - GF + ) ) - E GFE + ) ) - ( GFE- + ) / GFE- + ) / ) GFE- + ) / ) D GFE-D + ) / ) + GFE-D + ) / ) + C GFE-DC + ) / ) +
  • 3. ( GFE-DC+ + ) / * GFE-DC+ + ) / * ) GFE-DC+ + ) / * ) B GFE-DC+B + ) / * ) + GFE-DC+B + ) / * ) + A GFE-DC+BA + ) / * ) + ( GFE-DC+BA+ + ) / * ( GFE-DC+BA+*/ + (empty) GFE-DC+BA+*/+ (empty) - Now pop-out Prefix_Stack to output (or simply reverse). Prefix expression is + / * + A B + C D – E F G PART B
  • 4. - First I’m assigning values to all operands. A = 14 B = 12 C = 10 D = 8 E = 6 F = 4 G = 2 - Evaluating Infix expression using above values. ( (14+12) * (10+8) / (6-4) ) + 2 ( 26 * 18 / 2 ) + 2 ( 468 / 2 ) + 2 ( 234 ) + 2 236 - Evaluating Infix expression using above values. + / * + 14 12 + 10 8 - 6 4 2 (14+2 & 10+8 & 6-4) + / * 26 18 2 2 (26 * 18) + / 468 2 2 (468 / 2) + 234 2 (234 + 2) 236 - Both are same, so our conversion is correct! PART C
  • 5. Arr = (Infix Expression) Set loop_counter to length_ of_ Arr do character = arr[loop_counter] if character is operator push character to prefix_stack if character is ‘)’ push character to stack if character is ‘(’ do pop character and push it to prefix_stack until character equals ‘(‘ if character is operator if character_precedence is greater OR is equal to stack[top]_ precedence push to stack else do pop from stack and push to prefix_stack until condition satisfices loop_counter = loop_counter - 1 While loop_counter IS NOT EQUAL to 0 Pop out prefix_stack and display each element