0% found this document useful (0 votes)
6 views2 pages

C Stack Operations: Push, Pop, Peek

The document is a C program that implements a stack data structure with basic operations such as push, pop, find peek, and display. It provides a main menu for user interaction to perform these operations until the user chooses to exit. The program includes error handling for stack overflow and underflow conditions.

Uploaded by

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

C Stack Operations: Push, Pop, Peek

The document is a C program that implements a stack data structure with basic operations such as push, pop, find peek, and display. It provides a main menu for user interaction to perform these operations until the user chooses to exit. The program includes error handling for stack overflow and underflow conditions.

Uploaded by

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

#include <stdio.

h>
#define size 10
void find_peek();
void push(int);
void pop();
void display();
int stack[size];
int var,cho,top=0;
void main()
{
clrscr();
do{
printf("MAINMENU\[Link] \[Link] \n3.Find_peek \[Link]\[Link]. \n");
printf("Enter the choice :");
scanf("%d",&cho);
switch(cho){
case 1:
printf("Enter the variable:");
scanf("%d",&var);
push(var);
break;
case 2:
pop();
break;
case 3:
find_peek();
break;
case 4:
display();
break;
}
}while(cho!=5);
}
void push(int ele)
{
if(top>=size)
printf("The stack is overflow\n");
else
stack[top++]=ele;
}
void pop()
{
if(top==0)
printf("The stack is underflow\n");
else
printf("The popped element is %d\n",stack[--top]);
}
void find_peek()
{
if(top==0)
printf("The stack is empty\n");
else
printf("The peek element is %d\n",stack[top-1]);
}
void display()
{
int i;
if(top==0)
printf("The stack is empty\n");
else{
for(i=top-1;i>=0;i--)
printf("\n%d",stack[i]);
printf("\n");
}
}

You might also like