Question
(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
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