Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a Stack abstract data type The Stack class should include the following methods: push(item) function to add a new item to the stack pop()

Create a Stack abstract data type The Stack class should include the following methods: push(item) function to add a new item to the stack pop() function to remove the top item from the stack peek() to return the top item in the stack is_empty() to test whether the stack is empty size() to tell the size (number of items) in the stack Create a html_checker function The function: Takes a string of HTML code as argument; Returns true if all tags are balanced; false if otherwise. Here is what the function should do: Create a new Stack object; Use the split() method of a string to split it into text lines; Create a loop to read the text lines, and for each text line: o If the text line matches an opening tag (e.g.

), add the tag name (e.g. h1) to the stack; o If the text line is ordinary content without a HTML tag, skip the line; o If the text line is a closing tag (e.g.

), check whether the stack is empty(): The HTML code is unbalanced if stack is currently empty; If not empty, use pop() to read and remove the top item from stack: The top item/tag matches the current closing tag, then the HTML code is balanced (true); Otherwise, the HTML code is unbalanced (false). Program Execution Create two variables, one with balanced HTML code and the other with unbalanced HTML code. Run the html_checker function with each of the two variables as argument to test the program.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Secrets Of Analytical Leaders Insights From Information Insiders

Authors: Wayne Eckerson

1st Edition

1935504347, 9781935504344

More Books

Students also viewed these Databases questions

Question

Knowledge of project management (PMI) teachings

Answered: 1 week ago