Question: Problem1: (5 points) As discussed in lectures, please write C codes for the following algorithm: Algorithm ParenMatch(X,n): Input: An array X of n tokens, each
Problem1: (5 points) As discussed in lectures, please write C codes for the following algorithm: Algorithm ParenMatch(X,n): Input: An array X of n tokens, each of which is either a grouping symbol, a variable, an arithmetic operator, or a number Output: true if and only if all the grouping symbols in X match Let S be an empty stack for i-0 to n-1 do if XTi] is an opening grouping symbol thern S.push(Xil) if SisEmpty0 then if S.pop0 does not match the type of Xi] then else if XIil is a closing grouping symbol then return false fnothing to match withj return false (wrong type if S.isEmpty0 then return true (every symbol matchedj else return false fsome symbols were never matchedj Requirement: (1) Write C codes to implement the abovementioned algorithm
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
