Below is a function post fixEval that is supposed to read a queue of char tokens and evaluates them as postfix notation

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Below is a function post fixEval that is supposed to read a queue of char tokens and evaluates them as postfix notation

Post by answerhappygod »

Below Is A Function Post Fixeval That Is Supposed To Read A Queue Of Char Tokens And Evaluates Them As Postfix Notation 1
Below Is A Function Post Fixeval That Is Supposed To Read A Queue Of Char Tokens And Evaluates Them As Postfix Notation 1 (241.69 KiB) Viewed 59 times
Below is a function post fixEval that is supposed to read a queue of char tokens and evaluates them as postfix notation (assuming there are only has * and + operations). If the postfix expression isn't formatted correctly it should print a warning to the user and return -1. Otherwise you should return value produced by the expression. The program should not leak any memory. Example: input: 5 3 2*1+ * output: 35 Since 5* ((3 * 2) + 1) = 5* (6+1) = 5 * 7 = 35 1 int *postfixEval( Queue *pq ){ Stack ps = createStack(); 2 3 4 while( isEmpty (pq) ) { char sym = dequeue ( ps); 5 6 7 if( sym != '+ || sym != '*') push( ps, next ); 8 9 10 11 12 13 else{ char y = pop( ps); char x = pop( ps ); if ( sym == "+" ) push( ps, x+y); else push( ps, x*y); } 14 15 16 17 18 } 19 20 int ret = top( ps); 21 22 23 if( !empty(ps)){ scanf( "Postfix expression formatted incorrectly\n"); return -1; } 24 25 26 27 freeQueue( pq); return ret; 28 29 }
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply