Question
Complete C code functions for all 6 cases. provide pseudocodes for each function as well. #include #include #define Max_Size 5 void push(int s[], int *p_top,
#include
#include
#define Max_Size 5
void push(int s[], int *p_top, int value);
void printCurrentStack(int s[], int *p_top);
int main()
{
int element, choice;
int top=0;
int n;
int *p_top=⊤
int s[]={};
while(1)
{
printf("Stack Operations. ");
printf("1. Push. ");
printf("2. Pop. ");
printf("3. Peek. ");
printf("4. IsEmpty. ");
printf("5. Print Current Stack. ");
printf("6. Exit. ");
printf("Enter your choice. ");
scanf("%d",&choice);
switch (choice)
{
case 1:
if (*p_top == Max_Size)
{
printf("Error: Overflow ");
printCurrentStack(s, p_top);
}
else {
printf("Enter the element to Push. ");
scanf("%d", &element);
push(s, p_top, element);
}
break;
case 2:
case 3:
case 4:
case 5:
printCurrentStack(s, p_top);
break;
case 6:
exit(1);
}
}
}
void push(int s[], int *p_top, int value) {
s[(*p_top)] = value;
(*p_top)++;
printCurrentStack(s, p_top);
}
void printCurrentStack(int s[], int *p_top) {
if ((*p_top) == 0) {
printf("The stack is empty. ");
return;
}
printf("There are %d elements currently in the stack. ", (*p_top));
for (int i = (*p_top) - 1; i >= 0; i--)
printf("%d ", s[i]);
printf(" ");
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started