QUEUE

If you have any queries please leave a message here
Your Message
×


A queue is a particular kind of collection in which the entities in the collection are keep in order and the principal operations on the collection are the addition of entities to the rear terminal position and removal of entities from the front terminal position. This makes the queue a First In First Out(FIFO) data structure.







Linear Queue Programming in C using Array
/* Header-File declaration */
#include<stdio.h>
#include<stdlib.h>

/* Global variable declaration */
int a[100], rear=-1, front=0;
/* Global function declaration */
void insert(int n);
int removeData();
void print();

void main()
{
int choice,num,retn;
/* Infinite loop */
while(1)
{
printf("\n Press 1 for insert operation");
printf("\n Press 2 for delete operation");
printf("\n Press 3 for display queue elements");
printf("\n Press 4 for exit window");
printf("\n Enter your choice...");
scanf("%d", &choice);
switch(choice)
{
case 1:
printf("\n Enter the number...");
scanf("%d", &num);
insert(num);
break;
case 2:
retn=removeData();
if(rear > front)
printf("\n Detete item is = %d",retn);
break;
case 3:
print();
break;
case 4:
exit(0); /* Exit from infinite loop */
break;
default:
printf("\n Wrong Input");
}
}
}

/* Insert operation */
void insert(int n)
{
/* Check whether the queue is full or not */
if(rear == 99)
{
printf("\n Queue overflow");
}
else
a[++rear]=n;
}

/* Remove operation */
int removeData()
{
int r=0;
if(rear < front)
printf("\n Queue underflow");
else
if(rear == front)
{
printf("\n Detete item is = %d",a[front]);
front++;
}
else
{
r=a[front];
front++;
}
return r;
}

/* Display data */
void print()
{
int i;
if(rear < front)
printf("\n\n No element has to display");
else
{
for(i=front; i<=rear; i++)
printf("%d\t",a[i]);
}
}



Linear Queue Programming in C using Linked List
/* Header-File declaration */
#include<stdio.h>
#include<stdlib.h>

/* Structure declaration */
struct Queue
{
int number;
struct Queue *next;
};
/* Global variable declaration */
struct Queue *head,*tail,*node;

/* Global function declaration */
void insert(int n);
int removeData();
void print();

void main()
{
int choice, num, retn;
head=NULL;
tail=NULL;
/* Infinite loop */
while(1)
{
printf("\n Press 1 for insert operation");
printf("\n Press 2 for delete operation");
printf("\n Press 3 for display queue elements");
printf("\n Press 4 for exit window");
printf("\n Enter your choice...");
scanf("%d", &choice);
switch(choice)
{
case 1:
printf("\n Enter the number...");
scanf("%d", &num);
insert(num);
break;
case 2:
retn=removeData();
if(head != NULL)
printf("\n Detete item is = %d",retn);
break;
case 3:
print();
break;
case 4:
exit(0); /* Exit from infinite loop */
default:
printf("\n Wrong Input");
}
}
}

/* Insert operation */
void insert(int n)
{
if(head == NULL)
{
head=(struct Queue *) malloc(sizeof(struct Queue));
head->number=n;
head->next=NULL;
tail=head;
}
else
{
node=(struct Queue *) malloc(sizeof(struct Queue));
node->number=n;
node->next=NULL;
tail->next=node;
tail=tail->next;
}
}

/* Remove operation */
int removeData()
{
int r=0;
if(head == NULL)
printf("\n Queue underflow");
else
if(head == tail)
{
r=head->number;
printf("\n Detete item is = %d",r);
head=NULL;
tail=NULL;
}
else
{
r=head->number;
head=head->next;
}
return r;
}

/* Display data */
void print()
{
int i;
if(head == NULL)
printf("\n No element has to display");
else
{
node=head;
while(node != NULL)
{
printf("%d\t",node->number);
node=node->next;
}
}
}



Circular Queue Programming in C using Array
/* Header-File declaration */
#include<stdio.h>
#include<stdlib.h>

/* Global variable declaration */
int a[100], rear=-1, front=0, count=0;
/* Global function declaration */
void insert(int n);
int removeData();
void print();

void main()
{
int choice,num,retn;
/* Infinite loop */
while(1)
{
printf("\n Press 1 for insert operation");
printf("\n Press 2 for delete operation");
printf("\n Press 3 for display queue elements");
printf("\n Press 4 for exit window");
printf("\n Enter your choice...");
scanf("%d", &choice);
switch(choice)
{
case 1:
printf("\n Enter the number...");
scanf("%d", &num);
insert(num);
break;
case 2:
retn=removeData();
if(front > 0 || rear > -1)
printf("\n Detete item is = %d",retn);
break;
case 3:
print();
break;
case 4:
exit(0); /* Exit from infinite loop */
break;
default:
printf("\n\n\n Wrong Input");
}
}
}

/* Insert operation */
void insert(int n)
{
/* Check whether the queue is full or not */
if((front == 0 && rear == 99) || (front == rear+1 && count == 1))
{
printf("\n Queue overflow");
}
else
if(rear == 99)
{
rear=0;
a[rear]=n;
count=1;
}
else
a[++rear]=n;
}

/* Remove operation */
int removeData()
{
int r=0;
if(front == 0 && rear == -1)
printf("\n Queue underflow");
else
if(front == rear)
{
printf("\n Detete item is = %d",a[front]);
rear=-1;
front=0;
count=0;
}
else
{
r=a[front];
if(front == 99)
front=0;
else
front++;
}
return r;
}

/* Display data */
void print()
{
int i;
if(front == 0 && rear == -1)
printf("\n\n No element has to display");
else
if(front <= rear)
{
for(i=front; i<=rear; i++)
printf("%d\t",a[i]);
}
else
{
for(i=front; i<=99; i++)
printf("%d\t",a[i]);
for(i=0; i<=rear; i++)
printf("%d\t",a[i]);
}
}


ABOUT US

QuestionSolves.com is an educational website that helps worldwide students in solving computer education related queries.

Also, different software like Visual Studio, SQL Server, Oracle etc. are available to download in different versions.

Moreover, QuestionSolves.com provides solutions to your questions and assignments also.


MORE TOPIC


Windows Command

UNIX Command

IGNOU Assignment Solution

IGNOU Question Paper Solution

Solutions of Different Questions


WHAT WE DO


Website Devlopment

Training

Home Learning

Provide BCA, MCA Projects

Provide Assignment & Question Paper Solution


CONTACT US


Follow Us