7. Program to implement Stack operations using arrays.
#include<stdio.h>
#include<conio.h>
#define size 5
int a[size];
int top=-1,val;
void push(val)
if(top==size-1)
printf("OVERFLOW");
else
top++;
a[top]=val;
void pop()
if(top==-1)
printf("UNDERFLOW");
else
printf("the deleted value is %d \t",a[top]);
top--;
void display()
{
int i;
if(top>-1)
printf("the values are:\n");
for( i=top;i>=0;i--)
printf("%d\t",a[i]);
else
printf("nothing to print");
void main()
int choice, val;
clrscr();
while(1)
printf("\n 1.PUSH\n 2.POP\n 3.DISPLAY\n 4.EXIT\n");
printf("Enter your choice:\n");
scanf("%d",&choice);
switch(choice)
case 1: printf("Enter the value to be inserted \n");
scanf("%d", &val);
push(val);
break;
case 2: pop();
break;
case 3: display();
break;
case 4: exit(0);
default: printf("invalid input");
getch();
}
8. Program to implement Queue operations using arrays.
#include<stdio.h>
#include<conio.h>
#define size 3
int ele,i;
int queue[size],front=-1,rear=-1;
void insert()
if(rear==size-1)
printf("Overflow");
else
if(front==-1)
front=0;
printf("Enter the elements to be inserted into the queue:\n");
scanf("%d",&ele);
rear++ ;
queue[rear]=ele;
void deletee()
if(rear==0||front>rear)
printf("underflow");
}
else
ele=queue[front];
printf("the deleted element is %d\n",ele);
front++;
void display()
if (rear==-1||front>rear)
printf("queue is empty\n");
else
printf("the elements in the queue are:\n");
for(i=front;i<=rear;i++)
printf("%d\t",queue[i]);
int main()
int ch;
clrscr();
while(1)
printf("\n1.INSERT\n 2.DELETE\n 3.DISPLAY\n 4.EXIT\n");
printf("enter your choice\n");
scanf("%d",&ch);
switch(ch)
case 1: insert(ele);
break;
case 2: deletee();
break;
case 3: display();
break;
case 4: exit(0);
break;
default: printf("invalid choice\n");