Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Python Language Create a Stack abstract data type The Stack class should include the following methods: - push(item) function to add a new item to
Python Language
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 - pop0 function to remove the top item from the stack - peek() to return the top item in the stack - is empty0 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: If the text line matches an opening tag (e.g. h> ), add the tag name (e.g. "hl") to the stack; If the text line is ordinary content without a HTML tag, skip the line; If the text line is a closing tag (e.g. h ), check whether the stack is empty 0 : - 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. Week 1 Assignment 1 Please solve the following problem with programming using proper data structures. A similar application to the parentheses matching problem comes from hypertext markup language (HTML). In HTML, tags exist in both opening and closing forms and must be balanced to properly describe a web document. This very simple HTML document: is intended only to show the matching and nesting structure for tags in the language. Write a program that can check an HTML document for proper opening and closing tags. To simplify the problem, we suppose the opening and closing tags are provided in separate lines without indentation (shown in the green box on the right above). Consult the example on parentheses matching in lecture slides or the more general balanced symbol example in section 3.7 of the book at Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started