Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLZ in c++ code. Suppose we have a Stack that can grow indefinitely (for example, the push method has been fixed to double the size

PLZ in c++ code.

Suppose we have a Stack that can grow indefinitely (for example, the push method has been fixed to double the size of the array when at capacity instead of throwing a StackFullException). We want to create a second Stack data structure, which I promise will always contain only comparable items (e.g., integers, strings). We also want to add a function findMin to the Stack interface that will return the smallest element currently in the stack. We could implement this by searching the array, but that takes time linear in the number of elements in the Stack. Explain how you would change the Stack data structure to allow for this function to run in O(1) time. If you are storing additional private member data, state what else you are storing. If you are changing existing functions push, pop, or top (or the constructor/size functions), explain briefly how you are changing them. Their running times must still be O(1); for example, you cannot search the full stack for the newest min at every push and pop.

You may assume that there will never be a duplicate item pushed to the Stack.

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

Concepts of Database Management

Authors: Philip J. Pratt, Mary Z. Last

8th edition

1285427106, 978-1285427102

More Books

Students also viewed these Databases questions