Please, Add display function that prints the stack using FIFO(first in first out) {printed in the sequence they were entered} #include #include #include #define max 5 int push(char stack[max][80], int *top, char data[80]) { if(*top == max -1) return(-1); else { *top = *top + 1; strcpy(stack[*top], data); return(1); } } int pop(char stack[max][80], int *top, char data[80]) { if(*top == -1) return(-1); else { strcpy(data, stack[*top]); *top = *top - 1; return(1); } } int main() { char stack[max][80], nm[80]; int top,ch,reply; top = -1; // Initialize Stack printf("\tMENU"); printf("\n----------------------------\n"); printf(" 1. PUSH\n"); printf(" 2. POP\n"); printf(" 3. EXIT\n"); printf("----------------------------\n"); while(1) { printf("Choose operation : "); scanf("%d", &ch); switch (ch) { case 1 : // push printf("\nEnter string : "); scanf("%s",nm); reply = push(stack,&top,nm); if(reply == -1) printf("\n Stack is Full.\n"); else printf("'%s' is Pushed in Stack.\n\n",nm); break; case 2 : // pop reply = pop(stack, &top,nm); if(reply == -1) printf("\n Stack is Empty \n"); else printf("Popped string is : %s\n",nm); printf("\n"); break; case 3 : exit(0); default: printf("Invalid operation \n"); } } return 0;

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Please, Add display function that prints the stack using FIFO(first in first out) {printed in the sequence they were entered}

 

#include<stdio.h>

#include<string.h>
#include<stdlib.h>
#define max 5
int push(char stack[max][80], int *top, char data[80])
{
if(*top == max -1)
return(-1);
else
{
*top = *top + 1;
strcpy(stack[*top], data);
return(1);
}
}
int pop(char stack[max][80], int *top, char data[80])
{
if(*top == -1)
return(-1);
else
{
strcpy(data, stack[*top]);
*top = *top - 1;
return(1);
}
}
int main()
{
char stack[max][80], nm[80];
int top,ch,reply;
top = -1; // Initialize Stack
printf("\tMENU");
printf("\n----------------------------\n");
printf(" 1. PUSH\n");
printf(" 2. POP\n");
printf(" 3. EXIT\n");
printf("----------------------------\n");
while(1)
{
printf("Choose operation : ");
scanf("%d", &ch);
switch (ch)
{
case 1 : // push
printf("\nEnter string : ");
scanf("%s",nm);
reply = push(stack,&top,nm);
if(reply == -1)
printf("\n Stack is Full.\n");
else
printf("'%s' is Pushed in Stack.\n\n",nm);
break;
case 2 : // pop
reply = pop(stack, &top,nm);
if(reply == -1)
printf("\n Stack is Empty \n");
else
printf("Popped string is : %s\n",nm);
printf("\n");
break;
case 3 :
exit(0);
default:
printf("Invalid operation \n");
}
}
return 0;
}

Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY