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