0% found this document useful (0 votes)
2 views1 page

Stack Program Code Output

The document contains a C program that implements a stack with operations for pushing, popping, and displaying elements. It includes a menu-driven interface allowing users to interact with the stack and handle overflow and underflow conditions. The program demonstrates the stack operations through a series of user inputs and outputs.

Uploaded by

vinitsahare362
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Stack Program Code Output

The document contains a C program that implements a stack with operations for pushing, popping, and displaying elements. It includes a menu-driven interface allowing users to interact with the stack and handle overflow and underflow conditions. The program demonstrates the stack operations through a series of user inputs and outputs.

Uploaded by

vinitsahare362
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PROGRAM CODE PROGRAM OUTPUT

#include #include int stack[6]; int top=-1; void push() { STACK MENU 1. Push 2. Pop 3. Display 4. Exit Enter
int value; if(top==6-1) printf("stack overflow/cannot choice: 1 Enter value: 32 32 pushed into stack Enter
push elements"); else { printf("Enter the value to choice: 1 Enter value: 45 45 pushed into stack Enter
push:"); scanf("%d",&value;); top++; stack[top]=value; choice: 1 Enter value: 56 56 pushed into stack Enter
printf("%d pushed into stack",value); } } void pop() { choice: 1 Enter value: 88 88 pushed into stack Enter
if(top==-1) printf("Stack Underflow/ Cannot pop choice: 1 Enter value: 30 30 pushed into stack Enter
element."); else { printf("popped element %d", choice: 3 30 88 56 45 32 Enter choice: 2 popped
stack[top]); top--; } } void display() { int i; if(top==-1) element 30 Enter choice: 3 88 56 45 32 Enter choice:
printf("stack is empty"); else { for(i=top;i>=0;i--) 2 popped element 88 Enter choice: 2 popped element
printf("%d", stack[i]); } } int main() { int choice; while(1) 56 Enter choice: 2 popped element 45 Enter choice: 2
{ printf("STACK MENU"); printf("[Link]"); popped element 32 Enter choice: 2 Stack Underflow
printf("[Link]"); printf("[Link]"); printf("[Link]"); Enter choice: 3 stack is empty
scanf("%d",&choice;); switch(choice) { case 1: push();
break; case 2: pop(); break; case 3: display(); break;
case 4: exit(0); default: printf("Invalid choice"); } } }

You might also like