c-record - 9) stack
#include<stdio.h>
#include<conio.h>
#define SIZE 3
void push();
void pop();
void peek();
void display();
int stack[SIZE],top=-1,ele;
void main()
{
int ch;
clrscr();
printf("\nMenu\n1.Push\n2.Pop\n3.Peek\n4.Display\n5.Exit\n");
while(1)
{
printf("\nEnter your choose Operator : ");
scanf("%d",&ch);
switch(ch)
{
case 1 :push();
break;
case 2 :pop();
break;
case 3 :peek();
break;
case 4 :display();
break;
default:exit();
}
}
getch();
}
void push()
{
if(top==SIZE-1)
printf("\nStack is full");
else
{
top++;
printf("\nEnter the element to be inserted into the stack : ");
scanf("%d",&ele);
stack[top]=ele;
}
}
void pop()
{
if(top==-1)
printf("\nStack is empty");
else
{
ele=stack[top];
printf("\nThe deleted element from the stack : %d ",ele);
top--;
}
}
void peek()
{
if(top==-1)
printf("\nStack is empty");
else
{
ele=stack[top];
printf("\nThe top most element of the stack : %d ",ele);
}
}
void display()
{
int i;
if(top==-1)
printf("\nStack is empty");
else
{
printf("\nThe element of the stack :\n");
for(i=top;i>=0;i--)
printf("%d\n",stack[i]);
}
}
note:- display the four image outputs continue write single output
1) output:-
alt +f9 ------ run and
ctrl+f9 ------ compile
Comments
Post a Comment