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

Stack Program Using Array

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)
6 views7 pages

Stack Program Using Array

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
You are on page 1/ 7

//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
\n1.Push\n2.Pop\n3.Display\n4.Peak\n5.exit");
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