#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define MAX 5
int stack[MAX], top;
void display()
{
int i;
printf("The Elements in Stack are:\n");
for(i=0;i<=top;i++)
{
printf("%d\n",stack[i]);
}
}
void push()
{
char no;
if(top==MAX-1) printf("Stack Overflow");
else
{
top=top+1;
printf("Enter a Number: ");
scanf("%d",&no);
stack[top]=no;
display();
}
}
void pop()
{
if(top==-1) printf("Stack Underflow");
else
{
top--;
display();
}
}
void main()
{
clrscr();
char ch=1;
top=-1;
char choice;
printf("Working with Data Structure\n\n");
printf("Menu\n\n1. Push\n2. Pop\n");
printf("0. Exit");
while(ch)
{
printf("\n\nEnter your choice: \n");
choice=getch();
switch(choice)
{
case '1': push();
break;
case '2': pop();
break;
case '0': return;
default: printf("Wrong choice");
}
}
}
#include<conio.h>
#include<stdlib.h>
#define MAX 5
int stack[MAX], top;
void display()
{
int i;
printf("The Elements in Stack are:\n");
for(i=0;i<=top;i++)
{
printf("%d\n",stack[i]);
}
}
void push()
{
char no;
if(top==MAX-1) printf("Stack Overflow");
else
{
top=top+1;
printf("Enter a Number: ");
scanf("%d",&no);
stack[top]=no;
display();
}
}
void pop()
{
if(top==-1) printf("Stack Underflow");
else
{
top--;
display();
}
}
void main()
{
clrscr();
char ch=1;
top=-1;
char choice;
printf("Working with Data Structure\n\n");
printf("Menu\n\n1. Push\n2. Pop\n");
printf("0. Exit");
while(ch)
{
printf("\n\nEnter your choice: \n");
choice=getch();
switch(choice)
{
case '1': push();
break;
case '2': pop();
break;
case '0': return;
default: printf("Wrong choice");
}
}
}
0 comments:
Post a Comment