Question: Hi, I'm looking for help for a C(NOT C++) program that utilizes stacks/hash tables that has thefollowing algorithm: The algorithm to determine if thestart and

Hi, I'm looking for help for a C(NOT C++) program that utilizes stacks/hash tables that has thefollowing algorithm:
The algorithm to determine if thestart and end-tags balance uses a Stack data structure to keeptrack of previously read start-tags. The algorithm is:
1. Readthe input until the beginning of a tag is detected. (i.e. tagsbegin with <: if the next character is a / (slash), then it isan end-tag; otherwise it is a start-tag).
2. Readthe tag's identity. (e.g. both tags and havethe same identity: 'x').
3. Ifthe tag was a start-tag, push it onto the Stack.
4.Otherwise, it is an end-tag. In this case, pop the Stack (whichcontains a previously pushed start-tag identity) and verify thatthe popped identity is the same as the the end-tag just processed.Note: if the stack cannot be popped (because it isempty), the input is invalid; the algorithm should STOP.
5. Ifthe identities do not match, the XML expression isinvalid. STOP.
6. Ifthey do match, then no error has been detected (yet!).
7. Ifthere is still input that has not yet been processed, go back tothe first step.
8. Otherwise (no moreinput) then the input is valid unless the Stack isnot empty. Indicate whether theinput is valid (Stack empty) or invalid and STOP.
Example of XML tags:
XML
Valid?
Explanation
Yes
"a" tags balance
Yes
"a" outer tags and "b" inner tags balance
No
"a" end-tags does not match start-tag ("b")
Yes
all tags balance
No
"Baker" end-tag does not matchstart-tag ("baker") (i.e. the tag names arecase-sensitive.)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!