10 points Question 2: Errors in Code .. Below is a function post fixEval that is supposed to read a queue of char tokens
Posted: Sat May 14, 2022 8:22 pm
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
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