STACK using array in c
#include<stdio.h>
#include<conio.h>
int arr[6],top=-1;
void insert()
{
// Check if it is not full then increment top and assign value in it.
if(!isfull())
{
int item;
printf("Enter Element\n");
scanf("%d",&item);
top++;
arr[top]=item;
}
else
printf("Full");
}
int isfull()
{
if(top==5)
return 1;
else
return 0;
}
int isempty()
{
if(top==-1)
return 1;
else
return 0;
}
void pop()
{
if(!isempty())
top--;
else
printf("Empty");
}
void peep()
{
if(!isempty())
{
int temp=top;
while(temp>-1)
{
printf("%d",arr[temp]);
temp--;
}}
}
void main()
{
int ch;
while(1)
{
printf("\n1 For Insert \n 2 For delete \n 3 to traverse \n 4 : Exit");
scanf("%d",&ch);
switch(ch)
{
case 1:
insert();
break;
case 2:
pop();
break;
case 3:
peep();
break;
case 4:
exit(1);
}
}
getch();
}
#include<conio.h>
int arr[6],top=-1;
void insert()
{
// Check if it is not full then increment top and assign value in it.
if(!isfull())
{
int item;
printf("Enter Element\n");
scanf("%d",&item);
top++;
arr[top]=item;
}
else
printf("Full");
}
int isfull()
{
if(top==5)
return 1;
else
return 0;
}
int isempty()
{
if(top==-1)
return 1;
else
return 0;
}
void pop()
{
if(!isempty())
top--;
else
printf("Empty");
}
void peep()
{
if(!isempty())
{
int temp=top;
while(temp>-1)
{
printf("%d",arr[temp]);
temp--;
}}
}
void main()
{
int ch;
while(1)
{
printf("\n1 For Insert \n 2 For delete \n 3 to traverse \n 4 : Exit");
scanf("%d",&ch);
switch(ch)
{
case 1:
insert();
break;
case 2:
pop();
break;
case 3:
peep();
break;
case 4:
exit(1);
}
}
getch();
}
0 Comments:
Post a Comment