10 points Question 2: Errors in Code .. Below is a function post fixEval that is supposed to read a queue of char tokens

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

10 points Question 2: Errors in Code .. Below is a function post fixEval that is supposed to read a queue of char tokens

Post by answerhappygod »

10 Points Question 2 Errors In Code Below Is A Function Post Fixeval That Is Supposed To Read A Queue Of Char Tokens 1
10 Points Question 2 Errors In Code Below Is A Function Post Fixeval That Is Supposed To Read A Queue Of Char Tokens 1 (375.66 KiB) Viewed 43 times
10 points Question 2: Errors in Code .. 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 } Continued on next page →

Find and describe at least 5 errors in the postfixEval function (this includes compile/runtime/logic errors). If at least 5 of your answers are correct you will receive full credit. There is no additional credit for finding more errors. Line # Short description 1 2 3 4 5 6 7
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply