Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Given a stack which can keep M numbers at most, write a new function for this stack class. Push N numbers and pop randomly. The
Given a stack which can keep M numbers at most, write a new function for this stack class. Push N numbers and pop randomly. The new function should tell if a given sequence of numbers is a possible pop sequence of a given input push sequence. Sample input: ("1,2,3,4,5", "4,5,3,2,1") should return: Yes, because you can push 1,2,3,4 and pop 4, and push 5, then pop 5,3,2,1. Note: "1,2,3,4,5" is the input push sequence, "4,5,3,2,1" is one possible pop sequence. "Given a stack" means you can assume you have a stack class with common attributes and functions implemented. Another sample input: ("1,2,3,4,5", "4,3,5,1,2") should return: No 1) write the new function 2) what's the big-O of your function
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