Friday, October 29, 2010

QUEUE -LINKED LIST IMPLEMENTATION


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.

----------------------------------------------------------------------------------------------

A C PROGRAM TO IMPLEMENT OPERATIONS IN QUEUE -LINKED LIST DEPLOYMENT

COMPILER EMPLOYED: DEV C++ COMPILER-4.9.9.2

SOURCE FILE SIZE :3 kb

EXE FILE SIZE :23 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:

#include
#include
#include
//STRUCTURE DEFINITION
struct LIST
{
int DATA;
struct LIST *NEXT;
};
/***** Redefining struct LIST as NODE *****/
typedef struct LIST NODE;
void ENQUEUE(NODE**,NODE**); /** Inserting character function in queue **/
void DEQUEUE(NODE**,NODE**); /** Deleting character function in queue **/
void DISPLAY(NODE*); /** Output displaying function **/



int main()
{
int OPT; /* Option inputing variable */
char ch; /* choice inputing variable */
NODE *FRONT; /* FRONT pointer in queue*/
NODE *REAR; /* REAR pointer in queue */
REAR=FRONT=NULL;
do
{
printf("\n QUEUE OPERATIONS BY DEPLOYMENT OF LINKED LISTS...");
printf("\n\n MENU:");
printf("\n[1].ENQUEUE DATA.");
printf("\n[2].DEQUEUE DATA. ");
printf("\n[3].TRAVERE QUEUE.");
printf("\n\n ENTER OPTION:");
scanf("%d",&OPT);
switch(OPT)
{
case 1:
printf("\n\n ENQUEUE OPERATION INVOKED...");
ENQUEUE(&FRONT,&REAR);
printf("\n\n ELEMENT ENQUEUED SUCCESSFULLY ...");
break;
case 2:
printf("\n\n DEQUEUE OPERATION INVOKED...");
DEQUEUE(&FRONT,&REAR);
printf("\n\n ELEMENT DEQUEUED SUCCESSFULLY ...");
break;
case 3:
printf("\n\n TRAVERSAL OPERATION INVOKED...");
DISPLAY(FRONT);
break;
}
printf("\n DO YOU WISH TO CONTINUE[y/n]:");
ch=(char)getche();
}while(ch=='Y' || ch=='y');

system("pause");
return 0;
}

void ENQUEUE(NODE **FRONT,NODE **REAR)
{
NODE *NEW; /* New NODE to be inserted */
NEW=(NODE*)malloc(sizeof(NODE));
NEW->NEXT=NULL;
printf("\n ENTER DATA TO ENQUEUE:");

scanf("%d",&(NEW->DATA));
if(*FRONT==NULL && *REAR==NULL)
{
*FRONT=NEW;
*REAR=NEW;
}
else
{

(*REAR)->NEXT=NEW;
*REAR=NEW;
}
}

void DEQUEUE(NODE **FRONT,NODE **REAR)
{
NODE *delnode; /* Node to be deleted */
if((*FRONT)==NULL && (*REAR)==NULL)
printf("\n ERROR!!!QUEUE IS EMPTY");
else
{
delnode=*FRONT;
(*FRONT)=(*FRONT)->NEXT;
free(delnode);
}
}
void DISPLAY(NODE *f)
{
int S=1;
while(f!=NULL)
{
printf("ELE%d:%d",S,f->DATA);
printf("<-");
f=f->NEXT;
S++;
}
}


----------------------------------------------------------------------------------------------
Your's friendly,

[MOHANRAM.G],
ADMIN...

0 comments:

Post a Comment