Hello. I need to write a program that reads in a .html file, and prints out only the html tags according to the order they are displayed, the catch is the program must check to make sure the tags are balanced as well, if they aren't an error message needs to be printed. I *must* use stack and queues for this. I have the basic understanding of how the program would work, but I'm slightly thrown off, especially with the queue.
Originally I thought the logic would be along the lines of: opening the html file, scan through untill a "<" is found, add that tag to the stack and continue untill the matching closing tag is found, if found remove from the stack and print to the output. However, it has to be printed as it would show on a webpage, ie:
<head>
<title>
</title>
</head>
<body>
<h1>
</h1>
</body>
so the method I'd use wouldn't work as the head and body tags are seperated, which I know is where the queue plays it's role but I just can't think of how I'd incorporate that. Any help or suggestions would be greatly appreciated. (and please, no actual code, just pseudocode or just general tips)