in C++
For this program, you are going to implement a stack using anarray and dynamic memory allocation.
A stack is a special type of data structure that takes in values(in our case integers) one at a time and processes them in aspecial order. Specifically, a stack is what's called afirst-in-last-out (FILO) data structure. That is to say, the firstinteger inserted into the stack is the last value to be processed.The last value in the stack is the first one processed.
A stack is used as a part of many different algorithms incomputer science. For now, when we say to \"process\" an integer onthe stack, all I want you to do is print out what the integer is tothe terminal, and then remove it from the array.
Here's a link for a visual on how it would work:https://www.cs.usfca.edu/~galles/visualization/StackArray.html
Here is how I want your program to work:
- Have the program present a menu where I can either:
- Insert a new integer onto the stack.
- Process an integer from the stack.
- Quit the program.
- Every time that you present the menu, please print out thecontents of the stack before I pick a menu option. If the stack isempty, please let the user know.
- The point of this assignment is to use dynamic memoryallocation. So you must use malloc at the start ofthe program to allocate memory for a single integer. Thenuse realloc for the remainder of the program. Staticallydeclaring arrays will result in no credit for the assignment!
- If I choose the second options, which is to process a node,please print out the value that is being processed and then userealloc to appropriately change the size of yourarray.
- Be sure to use the free function to release all memoryif I decide to quit the program.
You do not have to do this in a function. This can all be donein the main function if you like.
I've attached the output from my version of the program in thesampleoutput.txt file if you would like to see an exampleof what I'm looking for.
*****Extra credit: 10%*****
A queue is a similar data structure in which the first iteminserted into the queue is the first item processed (FIFO). After Ichoose to quit the stack loop, reallocate the array pointer back toa single integer and then repeat the program above, but so itprocesses the integers in the order of a queue rather than a stack.The output should indicate that we are now using a queue aswell.