Question: Write in C This assignment involves memory management with pointers and stacks. For this assignment, I want you to write a stack in C. A
Write in C


This assignment involves memory management with pointers and stacks. For this assignment, I want you to write a "stack" in C. A stack is a data structure where you "push(" items onto the stack and "pop" items off of the stack. It is essentially a Last-In, First-Out queue. For this stack, I want you to store integers. The initial stack should be made to be able to hold 5 items. If you try to push() an item to a full stack (that is, the stack has 5 items and you try and add a 6th item), then you should carefully reallocate to provide more memory for the stack, ensuring that you do all of the relevant error checking and ensure that items from the old stack are indeed copied. Use realloc() for this, I do not want you doing the memory copies yourself. The general rule is to double the memory in this type of situation, so you should be keeping track of the initial size of the stack, and then doubling it when the limit is hit. Also note that allocating too much memory is not a good thing, so when the amount of space used is
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
