Question: code in C Figure 7 . 1 3 in the textbook ( slide 3 4 / lesson 0 7 of the generic slides ) shows

code in C Figure 7.13 in the textbook (slide 34/ lesson 07 of the generic slides) shows the two functions pop and push that deal with a stack of characters. Write the program by completing the main program that does the following:
Call the push function three times.
Prints out the updated stack
Calls the pop function once
Print the updated stack again.
No need to write the algorithm for this problem, it is already given to you.
#include
#define STACK_EMPTY '0'
#define STACK_SIZE 20
void
push(char stack[],/* input/output - the stack */
char item, /* input - data being pushed onto the stack */
int *top,/* input/output - pointer to top of stack */
int max_size)/* input - maximum size of stack */
{
if (*top < max_size-1){
++(*top);
stack[*top]= item;
}
}
char
pop (char stack[],/* input/output - the stack */
int *top)/* input/output - pointer to top of stack */
{
char item; /* value popped off the stack */
if (*top >=0){
item = stack[*top];
--(*top);
} else {
item = STACK_EMPTY;
}
return (item);
}
int
main (void)
{
char s [STACK_SIZE];
int s_top =-1; // stack is empty
/* complete the program here */
return (0);
}

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!