0% found this document useful (0 votes)
2 views6 pages

Stack IU2441231784

The document contains a C program that implements a stack data structure with operations such as push, pop, peep, change, and display. It allows users to interact with the stack through a menu-driven interface. The program checks for overflow and underflow conditions during stack operations.

Uploaded by

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

Stack IU2441231784

The document contains a C program that implements a stack data structure with operations such as push, pop, peep, change, and display. It allows users to interact with the stack through a menu-driven interface. The program checks for overflow and underflow conditions during stack operations.

Uploaded by

useindus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

IU2441231784 Stack

#include<stdio.h>
#include<conio.h>
#define max 10 int
a[max], top = -1;
void push(); void
pop(); void peep();
void change(); void
display(); void
main()
{ int ch;
clrscr();
while(1) {
printf("\n1. PUSH \n2. POP \n3. PEEP \n4. CHANGE \n5. Display\n6. Exit \nEnter Your
Choice :"); scanf("%d",&ch); clrscr(); switch(ch)

{ case
1:

{ push(
);
break;
}
case 2:

{ pop(
);
break;
}
case 3:

{ peep(
);
break;
}
case 4:
{
change();
break;
}
case 5:

{ display(
); break;
}
IU2441231784 Stack

case 6:
{ exit(0); }
default: printf("\ninvalid
choice !!!"); } // switch close
getch();
}
//getch();
}

void push()
{ int data;
if(top==max-1)
{
printf("\nStack is Overflow.");
}
else
{
printf("\nEnter the Element:");
scanf("%d",&data); top++;
a[top]=data;
}
}

void pop()
{
if(top==-1)
{
printf("\nStack is Underflow.");
}

else
{
printf("\nPOP Element:%d",a[top]);
top--;
}
}
void display()
{ int
i;
if(top
>=0)
{
printf("\nElemets:");
for(i=top; i>=0; i--)
IU2441231784 Stack

{
printf("\n%d",a[i]);
}
}
else
{
printf("\nSTACK is Empty");
}
}
void peep()
{ int p; printf("\nEnter the
position : "); scanf("%d",&p);
if(top-p<=-1)
{
printf("\nSTACK is overflow !!!");
}
else
{
printf("\nThe Elements is : %d",a[top-p]);
}
}
void change()
{ int p,n; printf("\nEnter Position for
change : "); scanf("%d",&p); printf("\
nEnter the Number for change : ");
scanf("%d",&n); if(top-p<=-1)
{
printf("\nSTACK is overflow !!!");
}
else
{
a[top-p]=n;
printf("\nCHANGE successfull !!!");
}
}
IU2441231784 Stack
IU2441231784 Stack
IU2441231784 Stack

You might also like