Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
7 views

Queue Using Arrays

Uploaded by

eloziiopfoze
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Queue Using Arrays

Uploaded by

eloziiopfoze
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

/*queue using arrays */

#define MAX 10
int q[MAX];
int rear=0;
int front=0;
int full=0;
int empty=1;

void ins(int);
void print(void);
int del(void);

void main(void)

{ int opt,ch,y;
clrscr();
do
{
clrscr();
printf("\n1. Insert\n");
printf("\n2. Delete\n");
printf("\n3. Print\n");
printf("\n4. Exit\n");
printf("\n\n\t Enter your Choice\n");
scanf("%d",&opt);

switch(opt)
{
case 1:
printf("\nEnter item to insert \n");
scanf("%d", &y);
ins(y);
break;
case 2:
y=del();
printf("Deleted item is : %d" ,y);
break;
case 3:
printf("\nThe Given List is\n");
print();
}
printf("\n Continue 1/0");
scanf("%d",&ch);
}while(ch==1);
}
void print(void)
{
int i;
for(i=front; i<rear; i++)
printf("%d ," ,q[i]);
}

void ins(int x)
{

if(full)
{
printf("\nQueue Full");
return;
}
else
{
q[rear]=x;
rear++;
empty=0;
if(rear==MAX)
full=1;
}
return;
}

int del(void)
{ int x;

if(empty)
{
printf("\nQueue is Empty");
exit(0);
}
else
{
x=q[front];
front++;
full=0;
if(front==rear)
empty=1;
}
return(x);
}

You might also like