Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C programming Q:2. A) Given the conversion program from infix to postfix, trace the program on the given infix string and fill the table. (10

C programming
Q:2. A) Given the conversion program from infix to postfix, trace the program on the given infix string and fill the table. (10 pts)
(A+ (B*C-(D/E^F)*G)*H), where ^ is an exponential operator.
1. #include
2. #include
3. #include
4. #define SIZE 50
5. char s[SIZE];
6. int top=-1;
7. push(char elem)
8. {
9. s[++top]=elem;
10. }
11.
12. char pop()
13. {
14. return(s[top--]);
15. }
16.
17. int pr(char elem)
18. {
19. switch(elem)
20. {
21. case '#': return 0;
22. case '(': return 3;
23. case '+':
24. case '-': return 2;
25. case '*':
26. case '/': return 3;
27. Case ^: return 4;
28. }
29. }
30.
31. void main()
32. {
33. char infx[50],pofx[50],ch,elem;
34. int i=0,k=0;
35. clrscr();
36. printf(" Read the Infix Expression ? ");
37. scanf("%s",infx);
38. push('#');
39. while( (ch=infx[i++]) != '\0')
40. {
41. if( ch == '(') push(ch);
42. else
43. if(isalnum(ch)) pofx[k++]=ch;
44. else
45. if( ch == ')')
46. {
47. while( s[top] != '(')
48. pofx[k++]=pop();
49. elem=pop();
50. }
51. else
52. {
53. while( pr(s[top]) > pr(ch) )
54. pofx[k++]=pop();
55. push(ch);
56. }
57. }
58. while( s[top] != '#')
59. pofx[k++]=pop();
60. pofx[k]='\0';
61. printf(" Given Infix Expn: %s Postfix Expn: %s ",infx,pofx);
62. getch();
Symbol No
Scanned
Stack
Postfix expression
Description (what action was performed)
1.
(
2.
A
3.
+
4.
(
5.
B
6.
*
7.
C
8.
-
9.
(
10.
D
11.
/
12.
E
13.
^
14.
F
15.
)
16.
*
17.
G
18.
)
19.
*
20.
H
21.
)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

ISBN: 133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions

Question

Describe Table Structures in RDMSs.

Answered: 1 week ago