Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Task: Write a stack of integers that is implemented with a dynamically doubling array, that also halves its size when the extra space isnt

C++ Task: Write a stack of integers that is implemented with a dynamically doubling array, that also halves its size when the extra space isnt needed.

Requirements:

1. Implement a stack of integers with a dynamic array with a starting size of 5. Every time the stack fills all the available space in the array, the array should double its capacity. Every time the stack drops below half full, the array should halve its capacity, with a minimum length of 5. Your stack should implement the following functions: void push(int n); // example declaration The push function should insert a value onto the stack. If the stack is full, it should double its capacity. void pop(); // example declaration The pop function should remove the value at the top of the stack. If the stack is only half full, it should halve its capacity (down to a minimum capacity of 5). void print(); // example declaration The print function should print the contents of the stack.

2. Write a main function that creates an instance of your stack, then calls the functions defined in part (1) to add and remove elements from it. Clearly show that it can double and halve its capacity. Print the results.

3. Test your code to make sure that it is successfully changing the size of the array, and that it can handle any edge cases you can think o

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

Transactions On Large Scale Data And Knowledge Centered Systems X Special Issue On Database And Expert Systems Applications Lncs 8220

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Stephen W. Liddle ,Klaus-Dieter Schewe ,Xiaofang Zhou

2013th Edition

3642412203, 978-3642412202

More Books

Students also viewed these Databases questions

Question

The company openly shares plans and information with employees.

Answered: 1 week ago