A queue (pronounced /kjuː/) is a particular kind of collection in which the entities in the collection are kept in order and the principal (or only) 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. In a FIFO data structure, the first element added to the queue will be the first one to be removed. This is equivalent to the requirement that whenever an element is added, all elements that were added before have to be removed before the new element can be invoked. A queue is an example of a linear data structure.
Queues provide services in computer science, transport, and operations research where various entities such as data, objects, persons, or events are stored and held to be processed later. In these contexts, the queue performs the function of a buffer.
Queues are common in computer programs, where they are implemented as data structures coupled with access routines, as an abstract data structure or in object-oriented languages as classes. Common implementations are circular buffers and linked lists.
Theoretically, one characteristic of a queue is that it does not have a specific capacity. Regardless of how many elements are already contained, a new element can always be added. It can also be empty, at which point removing an element will be impossible until a new element has been added again.
A practical implementation of a queue, e.g. with pointers, of course does have some capacity limit, that depends on the concrete situation it is used in. For a data structure the executing computer will eventually run out of memory, thus limiting the queue size. Queue overflow results from trying to add an element onto a full queue and queue underflow happens when trying to remove an element from an empty queue.
A bounded queue is a queue limited to a fixed number of items.
----------------------------------------------------------------------------------------------
A C PROGRAM TO IMPLEMENT OPERATIONS IN QUEUE-ARRAY IMPLEMENTATION
COMPILER EMPLOYED: DEV C++ COMPILER-4.9.9.2
SOURCE FILE SIZE :2 kb
EXE FILE SIZE :22 kb
NOTE: PLEASE INCLUDE THE DESIRED HEADER FILE
---------------------------------------------------------------------------------------------
C PROGRAM SOURCE & EXE DOWNLOAD:
Click download button to download
DISCLAIMER: The following program cannot be ensured of perfection.so any flaws in the program can be notified in the comments section.
----------------------------------------------------------------------------------------------
CODE:
# define MAXSIZE 200
int QUEUE[MAXSIZE];
int FRONT, REAR;
int main()
{
void ENQ(int);
int DEQ();
int CH,OPT,i,num;
FRONT =0;
REAR = 0;
do
{
printf("\n QUEUE OPERATIONS BY IMPLEMENTATION OF ARRAYS");
printf("\n\n MAIN MENU:");
printf("\n[1].ENQUEUE DATA");
printf("\n[2].DEQUEUE DATA");
printf("\n[3].TRAVERSAL");
printf("\n\n OPTION:");
scanf("%d",&CH);
switch(CH)
{
case 1:
printf("\n\nQUEUE OPERATION INVOKED...");
printf("\nENTER DATA: ");
scanf("%d",&num);
ENQ(num);
break;
case 2:
i=DEQ();
printf("\n DEQUEUE OPERATION RESULT:%d ",i);
break;
case 3:
printf("\n\n TRAVERSAL OPERATION INVOKED...");
DISPLAY();
break;
default:
printf("\n\n INVALID CHOICE ... ");
break;
}
printf("\n\n DO YOU WISH TO CONTINUE:1~0:");
scanf("%d",&OPT);
}while(OPT==1);
printf("\n TERMINATING PROCESS...");
system("pause");
return 0;
}
//end of main
void ENQ(int a)
{
if(REAR>MAXSIZE)
{
printf("\nERROR!!! QUEUE FULL");
return;
}
else
{
QUEUE[REAR]=a;
REAR++;
printf("\n\n REAR : %d & FRONT :%d",REAR,FRONT);
}
}
int DEQ()
{
int a;
if(FRONT == REAR)
{
printf("\n\n QUEUE EMPTY");
return(0);
}
else
{
a=QUEUE[FRONT];
FRONT++;
}
return(a);
}
int DISPLAY()
{
int i=0,j=1;
if(REAR>=0)
{
printf("\n\n TRAVERSING QUEUE...");
while(i
----------------------------------------------------------------------------------------------
Your's friendly,
[MOHANRAM.G],
ADMIN...
0 comments:
Post a Comment