Recall the concepts of stacks. Implement a stack using arrays. Build a program that takes an infix statement and converts it to a postfix statement. If the statement is incorrect the program should inform the user that the input statement is incorrect. Otherwise it should return the postfix expression. After the statement has been successfully converted, the program should then evaluate this postfix expression and return the result.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Solve this problem of DSA using C language (using arrays) Problem Statement: Recall the concepts of stacks. Implement a stack using arrays. Build a program that takes an infix statement and converts it to a postfix statement. If the statement is incorrect the program should inform the user that the input statement is incorrect. Otherwise it should return the postfix expression. After the statement has been successfully converted, the program should then evaluate this postfix expression and return the result.
Problem Statement:
Recall the concepts of stacks. Implement a stack using arrays. Build a program that takes an infix
statement and converts it to a postfix statement. If the statement is incorrect the program should inform
the user that the input statement is incorrect. Otherwise it should return the postfix expression.
After the statement has been successfully converted, the program should then evaluate this postfix
expression and return the result.
(Infix to Postfix) Write a program that converts an infix expression into an
equivalent postfix expression.
The rules to convert an infix expression into an equivalent postfix expression
are as follows:
Suppose infx represents the infix expression and pfx represents the postfix
expression. The rules to convert infx into pfx are as follows:
Initialize pfx to an empty expression and also initialize the stack.
Get the next symbol, sym, from infx.
a.
b.
b.1.
If sym is an operand, append sym to pfx.
If sym is (, push sym into the stack.
If sym is ), pop and append all the symbols from the stack until the
most recent left parenthesis. Pop and discard the left parenthesis.
b.2.
b.3.
b.4.
If sym is an operator:
b.4.1. Pop and append all the operators from the stack to pfx that
are above the most recent left parenthesis and have pre-
cedence greater than or equal to sym.
b.4.2. Push sym onto the stack.
After processing infx, some operators might be left in the stack. Pop
and append to pfx everything from the stack.
C.
In this program, you will consider the following (binary) arithmetic opera-
tors: +, -, * , and /. You may assume that the expressions you will process are
error free.
Transcribed Image Text:Problem Statement: Recall the concepts of stacks. Implement a stack using arrays. Build a program that takes an infix statement and converts it to a postfix statement. If the statement is incorrect the program should inform the user that the input statement is incorrect. Otherwise it should return the postfix expression. After the statement has been successfully converted, the program should then evaluate this postfix expression and return the result. (Infix to Postfix) Write a program that converts an infix expression into an equivalent postfix expression. The rules to convert an infix expression into an equivalent postfix expression are as follows: Suppose infx represents the infix expression and pfx represents the postfix expression. The rules to convert infx into pfx are as follows: Initialize pfx to an empty expression and also initialize the stack. Get the next symbol, sym, from infx. a. b. b.1. If sym is an operand, append sym to pfx. If sym is (, push sym into the stack. If sym is ), pop and append all the symbols from the stack until the most recent left parenthesis. Pop and discard the left parenthesis. b.2. b.3. b.4. If sym is an operator: b.4.1. Pop and append all the operators from the stack to pfx that are above the most recent left parenthesis and have pre- cedence greater than or equal to sym. b.4.2. Push sym onto the stack. After processing infx, some operators might be left in the stack. Pop and append to pfx everything from the stack. C. In this program, you will consider the following (binary) arithmetic opera- tors: +, -, * , and /. You may assume that the expressions you will process are error free.
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Stack
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education