/* Programme to insert element in stack and queue */
#include<stdio.h>
#include<conio.h>
int a[5],i=-1;
void menu();
void push();
void pop();
void display();
void main()
{
clrscr();
menu();
getch();
}
void menu()
{
int choice;
clrscr();
printf("1. Push element\n2.Pop element\n3.Display element\n4.Exit\nEnter your choice(1-4):\n");
scanf("%d",&choice);
{
if(choice==1)
{
push();
}
else if(choice==2)
{
pop();
}
else if(choice==3)
{
display();
}
}
}
void push()
{
i++;
if(i<5)
{
printf("\nEnter values: ");
scanf("%d",&a[i]);
}
else
{
printf("Stack full");
i--;
}
}
/* for Queue
void pop()
{ int j;
if(i>=0)
printf("\n Pop element is= %d",a[i]);
for(j=0;j<=i;j++)
{
a[j]=a[j+1];
}
i--;
}
*/
void pop()
{
if(i>=0)
{
printf("\nPop element is: %d",a[i]);
i--;
}
else
{
printf("Stack Empty");
}
}
void display()
{
int j;
for(j=0;j<=i;j++)
{
printf("%d",a[j]);
}
}
#include<stdio.h>
#include<conio.h>
int a[5],i=-1;
void menu();
void push();
void pop();
void display();
void main()
{
clrscr();
menu();
getch();
}
void menu()
{
int choice;
clrscr();
printf("1. Push element\n2.Pop element\n3.Display element\n4.Exit\nEnter your choice(1-4):\n");
scanf("%d",&choice);
{
if(choice==1)
{
push();
}
else if(choice==2)
{
pop();
}
else if(choice==3)
{
display();
}
}
}
void push()
{
i++;
if(i<5)
{
printf("\nEnter values: ");
scanf("%d",&a[i]);
}
else
{
printf("Stack full");
i--;
}
}
/* for Queue
void pop()
{ int j;
if(i>=0)
printf("\n Pop element is= %d",a[i]);
for(j=0;j<=i;j++)
{
a[j]=a[j+1];
}
i--;
}
*/
void pop()
{
if(i>=0)
{
printf("\nPop element is: %d",a[i]);
i--;
}
else
{
printf("Stack Empty");
}
}
void display()
{
int j;
for(j=0;j<=i;j++)
{
printf("%d",a[j]);
}
}
0 $type={blogger}:
Post a Comment