Title: Implementing a Stack in C
Implement a stack to store and remove integers that will be read from a file. The data file contains a series of integers, one per line. There are two kinds of data in the file. Any integer greater than -99999 is an int that will be pushed onto your stack. Whenever you read -99999, this is a signal to pop your stack. The format of the data file is: . . . -99999 -99999 etc.
To create the initial stack, use malloc to allocate enough space to store 10 ints. Keep track of how many elements are on your stack. When your stack reaches capacity, you need to allocate more space to your stack (another 10 ints). You can use realloc or something else like malloc/copy/swap. You do not need to shrink your stack's capacity.
You are required to implement the following stack functions: push, pop, empty, and full.
- push takes an int parameter (the value to push onto the stack) and should probably return success or failure. Failure to push might happen if growing the stack fails.
- pop returns the int that was removed from the stack. Pop could be an error condition if the stack is empty when pop happens (again, the data file will not cause this).
- empty returns TRUE if the stack has no elements, otherwise FALSE.
- full returns TRUE if the stack does not have any room left, otherwise FALSE.
Your program must print "Assignment 2" and your name. Additionally, each time you read -99999 (i.e., each time you receive a signal to pop the stack), you should print the number of elements in the stack after popping and the integer that is popped off the stack. You should also print a message every time your stack grows.
For example, the program might print the following (NOTE: the data file results are fake):
Assignment 2
Problem 1 by
Number of elements after popping: 3
Integer popped: 22
Number of elements after popping: 5
Integer popped: 7
Stack capacity has grown from 10 elements to 20 elements
Number of elements after popping: 12
Integer popped: 14
DATA PROVIDED:
29
5
7295
103
394
-99999
-99999
48
12
839
55
-99999
28
91
523
-99999
289
32
414
-99999
829
21
9
45
299
101
-99999
3
88
718
501
-99999
39
89
47