0% found this document useful (0 votes)
21 views7 pages

Stack Implementation in C Programming

This document contains a C program that implements a stack data structure with operations such as push, pop, display, and peak. It defines a maximum capacity of 10 for the stack and provides a menu-driven interface for user interaction. The program includes error handling for stack overflow and underflow conditions.

Uploaded by

ryanyours8
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)
21 views7 pages

Stack Implementation in C Programming

This document contains a C program that implements a stack data structure with operations such as push, pop, display, and peak. It defines a maximum capacity of 10 for the stack and provides a menu-driven interface for user interaction. The program includes error handling for stack overflow and underflow conditions.

Uploaded by

ryanyours8
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 for Stack

#include<stdio.h>
#include<conio.h>
#define N 10
void push();
void pop();
void display();
void peak();
int s[N]; // s= Stack & N= Capacity.
int top=-1;
void main()
{
int c;
clrscr();
do
{
printf(" \nplease enter a choice
\[Link]\[Link]\[Link]\[Link]\[Link]");
scanf("%d",&c);
switch(c)
{
case 1: push();
break;
case 2: pop();
break;
case 3: display();
break;
case 4: peak();
break;
}
}while(c<=4);
if(c==5)
printf("\n Thankyou ");
getch();
}
void push()
{
int ele;
if(top==N-1)
printf(" the stack is full ");
else
{
printf(" enter the element ");
scanf("%d",&ele);
top++;
s[top]=ele;
printf(" the element entred is %d",s[top]);
}
}
void pop()
{
if(top==-1)
{
printf(" the stack is empty ");
}
else
{
printf(" element deleted is %d",s[top]);
top--;
}
}
void display()
{
int i;
if(top==-1)
printf(" the stack is empty ");
else
{
printf(" the elements are ");
for(i=0;i<=top;i++)
{
printf(" %d ",s[i]);
}
}
}
void peak()
{
printf(" element at peak is %d ",s[top]);
}
OUTPUT:-
1>Push:-

2>Pop:-

3>Display:-
4>Peak:-

You might also like