Question: Please Write C Code to Implement a Stack with Pointers with the following Guidelines in Mind! Modify your array-based stack to use a pointer-based stack.
Please Write C Code to Implement a Stack with Pointers with the following Guidelines in Mind!
Modify your array-based stack to use a pointer-based stack. All your original functions should remain in place, except they will now be using dynamically allocated nodes, as discussed in class. Define your anchor with the name "anchor", so we can quickly see it in your source. The functions below are the same as your original functions, but now must be modified to use a list. The stack can now grow to use up all available memory (you can have a huge number of elements in the stack). Your Node is a struct containing a "next" pointer as discussed in class, and a data item (a character) Push - adds one element to the top of the stack (accepts a character as input), returns an int: -1 if the stack is already full, 0 if the item was successfully added If the stack is empty (use "isFull" to find out) then create the first element of the stack Pop - removes the top element (if it exists) and returns: NULL if there are no elements (stack is empty) The element itself if there was one Top - does NOT remove anything. Returns a char with the value: NULL if there are no elements (stack is empty) The topmost element if there is one d. isFull - does NOT remove anything. Returns an int: 0 if there are no elements (the stack is empty) 1 if the stack is full -1 in all other cases Using the above functions, write a program that: a. Creates the anchor pointer for the stack of characters Uses your functions above to do the following: Accept input characters, 1 at a time until the symbol A is input Push each character onto the stack Output the stack (top to bottom) after all inputs have been received
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
