Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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,

Complete C code functions for all 6 cases. provide pseudocodes for each function as well. image text in transcribed

#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(" ");

}

define Max S123 vold pushint all. Int pta, st valual; vold printCurrentStackiant stl. in _tagli print". Iusty printl"S. Print Current StackW; printfl. Ext. printfl'Enter your chance."); 11 lip_top _in printer talent to Paulo CANT , bolesti puths, s_tas, alat; CAL: print Currant tacis, toal cit|ll: vold push it all, int wp_tas, ut value p_topil value; prin current stackis, a vold printourrontStackint [l, uttal printf "The tak sampty '); printf("There are valamits currently do the stacke", Cer_tup)); 0 ; 1- for fint i = lup_topl - 1; 1 printin". [1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Publishing With Filemaker Pro On The Web

Authors: Maria Langer

1st Edition

0201696657, 978-0201696653

More Books

Students also viewed these Databases questions