Write a program to show the PUSH method in Data Structure
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],max=10, i, n, tos , item;
printf("enter no. of elements=");
scanf("%d",&n);
printf("enter array elements\n");
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
tos=n;
if(tos>=max)
{
printf("overflow");
exit;
}
else
{
printf("enter item to be inserted=");
scanf("%d",&item);
tos=tos+1;
a[tos]=item;
printf("new stack\n");
for(i=1;i<=tos;i++)
{
printf("%d\n",a[i]);
}
}
}
#include<conio.h>
void main()
{
int a[10],max=10, i, n, tos , item;
printf("enter no. of elements=");
scanf("%d",&n);
printf("enter array elements\n");
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
tos=n;
if(tos>=max)
{
printf("overflow");
exit;
}
else
{
printf("enter item to be inserted=");
scanf("%d",&item);
tos=tos+1;
a[tos]=item;
printf("new stack\n");
for(i=1;i<=tos;i++)
{
printf("%d\n",a[i]);
}
}
}
Comments
Post a Comment