Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(Should be coded in Jupyter Notebook) Question 1: String matching In this question use the stack using built in list that is being taken. The

(Should be coded in Jupyter Notebook)

Question 1: String matching

In this question use the stack using built in list that is being taken. The last time which is isempty was added to check to see if the stack was empty. Write a program to see whether a string contains the following symbols.

[,],(,)

have matching brackets or not.

Hint:

When you input the string, go through character by character, and for each character if there is an opening bracket then push it to the stack. However if it is a closing bracket pop a character from the stack, and compare it to the corresponding opening bracket, make sure to return false if they don't correspond with each other. Also make sure you check to see if the stack is empty. If it is make sure to return true.

Stack implementation using python built in list

class Stack: def __init__(self): self.data = [] def size(self): return len(self.data) def push(self, data): self.data.append(data) def pop(self): return None if self.size() == 0 else self.data.pop() def peek(self): return None if self.size() == 0 else self.data[-1] def isEmpty(self): return (len(self.data) == 0)

Example: (x, result) Should return True or False

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

Records And Database Management

Authors: Jeffrey R Stewart Ed D, Judith S Greene, Judith A Hickey

4th Edition

0070614741, 9780070614741

More Books

Students also viewed these Databases questions

Question

Develop arguments for both sides of the Lau v. Nichols (1974) case.

Answered: 1 week ago

Question

Are these written ground rules?

Answered: 1 week ago

Question

How do Excel Pivot Tables handle data from non OLAP databases?

Answered: 1 week ago