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

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

Keep track of all the expected variables - the size of the stack, which item is the top of the stack, etc. You can do this in the main() and then call push() and pop() from the main, along with the code to expand or reduce the memory allocated.

Write a menu to allow people to push() and pop() from the stack. When they quit(), the stack memory should be freed. Test appropriately and submit.

For this assignment, I want you to write a "stack" in C.

Makefiles: For this assignment and every assignment after this assignment, unless otherwise indicated) you will need to use a Makefile. You should be creating a standard Makefile with targets for "all" and "clean". You should also create object files for each of the modules, and they should be set up as proper dependencies so that they are only compiled when needed. Make sure to "cat" the makefile when creating the script, and to include the makefile when you are submitting your code

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!