Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
Tutorial Three
Problem:
Problem 1: (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 X[i] is an opening grouping symbol then
S.push(X[i])
else if X[i] is a closing grouping symbol then
if S.isEmpty() then
return false {nothing to match with}
if S.pop() does not match the type of X[i] then
return false {wrong type}
if S.isEmpty() then
return true {every symbol matched}
else
return false {some symbols were never matched}
Requirement:
(1) Write C codes to implement the abovementioned algorithm.
(2) Write homework report to describe how you implement this algorithm
Submission:
Submit your homework assignment (C code and report in a zip file, with your student
ID+English name as zip file name) to class representative before October 12 23:59:59.