Welcome To Uday Satya Blog

14 . QUEUE ARRAY



/* *******************************************
          14 . TO PERFORM QUEUE OPERATIONS .
    ******************************************* */
#include<*stdio.h>
#include<*conio.h>
#include<*stdlib.h>
int a[20],f,r,ch,data,n;
void main()
{
int create();
void insert();
void del();
void display();
void option();
clrscr();
printf("\n enter the size of the queue : ");
scanf("%d",&n);
create();
printf("\n the queue created is : ");
display();
option();
printf("\n\n enter your choice : ");
scanf("%d",&ch);
while((ch>=1)&&(ch<=3))
{
switch(ch)
{
case 1 :  printf("\n enter the element to be inserted : ");
        scanf("%d",&data);
        insert();
        printf("\n the updated queue after insertion is : ");
        display();
        break;
case 2 :  del();
        printf("\n the updated queue after deletion is: ");
       display();
       break;
case 3 : printf("\n end of the program ");
       exit(1);
       break;
}
printf("\n\n enter your choice : ");
scanf("%d",&ch);
}
getch();
}
int create()
{
f=r=0;
while(r
{
printf("\n enter data into the queue : ");
scanf("%d",&data);
a[r]=data;
r++;
}
return(a[r]);
}
void display()
{
int cnt=f;
while(cnt
{
printf("%d\t",a[cnt]);
cnt++;
}
}
void insert()
{
if(r>20)
{
printf("\n queue over flow");
}
else
{
a[r]=data;
r++;
}
}
void del()
{
if(f==r)
{
printf("\n queue is empty");
}
else
{
f++;
}
}
void option()
{
printf("\n");
printf("\n1.insert");
printf("\n2.delete");
printf("\n3.exit");
}

output

 enter the size of the queue : 3

 enter data into the queue : 1

 enter data into the queue : 2

 enter data into the queue : 3

 the queue created is : 1       2       3

 1.insert
 2.delete
 3.exit

 enter your choice : 1

 enter the element to be inserted : 4

 the updated queue after insertion is : 1       2       3       4

 enter your choice : 2

 the updated queue after deletion is: 2     3       4

 enter your choice : 2

 the updated queue after deletion is: 3     4

 enter your choice : 2

 the updated queue after deletion is: 4

 enter your choice : 2

 the updated queue after deletion is:

 enter your choice : 3

 end of the program

0 comments:

Post a Comment