Write the program by completing the main program that doesthe following:1. Call the push function three times.2. Prints out the updated stack3. Calls the pop function once4. Print the updated stack again.No need to write the algorithm for this problem, it is already given to you.#include <stdio.h>#define STACK_EMPTY '0'#define STACK_SIZE 20voidpush(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;}}charpop (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);}intmain (void){char s [STACK_SIZE];int s_top = -1; // stack is empty/* complete the program here */return (0);}
Write the program by completing the main program that does
the following:
1. Call the push function three times.
2. Prints out the updated stack
3. Calls the pop function once
4. Print the updated stack again.
No need to write the
#include <stdio.h>
#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
Solved in 1 steps