Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Develop 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

Develop 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: 

 

  • Develop a new Stack object;
  • Use the split() method of a string to split it into text lines;
  • Develop a loop to read the text lines, and for each text line:
    • If the text line matches an opening tag (e.g.

      ), add the tag name (e.g. "h1") 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. ), 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 

 

Develop 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_2

Step: 3

blur-text-image_3

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

Concepts Of Programming Languages

Authors: Robert Sebesta

11th Edition

013394302X, 978-0133943023

More Books

Students also viewed these Algorithms questions

Question

What languages support negative subscripts?

Answered: 1 week ago

Question

What is an alias?

Answered: 1 week ago

Question

=+a. Draw a diagram of this RAID system.

Answered: 1 week ago

Question

=+b. Calculate the reliability at t 5 800,000 cycles.

Answered: 1 week ago