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);}

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter18: Stacks And Queues
Section: Chapter Questions
Problem 1TF
icon
Related questions
Question

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 algorithm for this problem, it is already given to you.
#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);

Expert Solution
steps

Step by step

Solved in 1 steps

Blurred answer
Knowledge Booster
Stack
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning