#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define size 100
struct stack
{
int top;
int item[size];
}s;
void push(struct stack *ps,int x)
{
if(ps->top==size-1)
{
printf("\nSTACK OVERFLOW");
return ;
}
else
ps->item[++(ps->top)]=x;
}
int pop(struct stack *ps)
{
if(ps->top==-1)
{
printf("\nSTACK UNDERFLOW");
return 0;
}
else
return(ps->item[ps->top--]);
}
void display()
{
int k;
printf("\n\n\tOUTPUT==>>");
for(k=s.top;k>=0;k--)
printf("\t%d",s.item[k]);
}
void main()
{
int i,j;
char ch;
clrscr();
s.top=-1;
while(1)
{
printf("\nPress 1 for push=");
printf("\nPress 2 for pop=");
printf("\nPress 3 for display=");
printf("\nPress 4 for exit=");
printf("\nEnter Choice=");
scanf("%d",&i);
clrscr();
printf("\n\n\t\t\t\t<<==STACK==>>\n\n");
switch(i)
{
case 1: printf("\nEnter element=");
scanf("%d",&j);
push(&s,j);
break;
case 2: printf("\nThe remove element is=%d",pop(&s));
break;
case 3: display();
break;
case 4: exit(0);
default:printf("\n\bWRONG CHOICE");
}
}
getch();
}
#include<conio.h>
#include<stdlib.h>
#define size 100
struct stack
{
int top;
int item[size];
}s;
void push(struct stack *ps,int x)
{
if(ps->top==size-1)
{
printf("\nSTACK OVERFLOW");
return ;
}
else
ps->item[++(ps->top)]=x;
}
int pop(struct stack *ps)
{
if(ps->top==-1)
{
printf("\nSTACK UNDERFLOW");
return 0;
}
else
return(ps->item[ps->top--]);
}
void display()
{
int k;
printf("\n\n\tOUTPUT==>>");
for(k=s.top;k>=0;k--)
printf("\t%d",s.item[k]);
}
void main()
{
int i,j;
char ch;
clrscr();
s.top=-1;
while(1)
{
printf("\nPress 1 for push=");
printf("\nPress 2 for pop=");
printf("\nPress 3 for display=");
printf("\nPress 4 for exit=");
printf("\nEnter Choice=");
scanf("%d",&i);
clrscr();
printf("\n\n\t\t\t\t<<==STACK==>>\n\n");
switch(i)
{
case 1: printf("\nEnter element=");
scanf("%d",&j);
push(&s,j);
break;
case 2: printf("\nThe remove element is=%d",pop(&s));
break;
case 3: display();
break;
case 4: exit(0);
default:printf("\n\bWRONG CHOICE");
}
}
getch();
}
No comments:
Post a Comment