An example that could possibly use an overwriting circular buffer is with multimedia. If the buffer is used as the bounded buffer in the producer-consumer problem then it is probably desired for the producer (e.g., an audio generator) to overwrite old data if the consumer (e.g., the sound card) is unable to momentarily keep up. Another example is the digital waveguide synthesis method which uses circular buffers to efficiently simulate the sound of vibrating strings or wind instruments.
The "prized" attribute of a circular buffer is that it does not need to have its elements shuffled around when one is consumed. (If a non-circular buffer were used then it would be necessary to shift all elements when one is consumed.) In other words, the circular buffer is well suited as a FIFO buffer while a standard, non-circular buffer is well suited as a LIFO buffer.
----------------------------------------------------------------------------------------------
A C PROGRAM TO IMPLEMENT OPERATIONS IN CIRCULAR QUEUE -LINKED LIST
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:
int ISFULL();
int ISEMPTY();
void ENQUEUE(int);
int DEQUEUE();
struct QUEUE
{
int ELE;
struct QUEUE *NEXT;
};
struct QUEUE *TEMP,*P,*FRONT,*REAR;
void INIT()
{
TEMP=NULL;
P=NULL;
FRONT=NULL;
REAR=NULL;
}
int main()
{
INIT();
int CH,OPT,EL;
do
{
printf("\n CIRCULAR QUEUE USING LINKED LIST IMPLEMENTATION");
printf("\n\n MENU:");
printf("\n [1]. ENQUEUE");
printf("\n [2]. DEQUEUE");
printf("\n [3].EXIT");
printf("\n\n OPTION:");
scanf("%d",&OPT);
switch(OPT)
{
case 1:
printf("\n ENQUEUE PROCESS INVOKED...");
if(ISFULL())
{
printf("\n QUEUE IS FULL");
break;
}
printf("\n\n ENTER AN ELEMENT:");
scanf("%d",&EL);
ENQUEUE(EL);
break;
case 2:
printf("\n DEQUEUE PROCESS INVOKED...");
if(ISEMPTY())
{
printf("\n QUEUE IS EMPTY");
break;
}
EL=DEQUEUE();
printf("\n ELEMENT DEQUEUED:%d",EL);
break;
case 3:
printf("\n\n TERMINATING....");
break;
default:
printf("\n\n INVALID OPTION");
break;
}
printf("\n DO YOU WISH TO CONTINUE?1~0:");
scanf("%d",&CH);
}while(CH==1);
return 0;
}
void ENQUEUE(int ELE)
{
P->NEXT=NULL;
P->ELE=ELE;
if(FRONT==NULL)
{
FRONT=P;
REAR=P;
return ;
}
REAR->NEXT=P;
REAR=P;
REAR->NEXT=FRONT;
}
int DEQUEUE()
{
int ELE;
ELE=FRONT->ELE;
TEMP=FRONT;
if(FRONT==REAR)
{
INIT();
}
else
{
FRONT=FRONT->NEXT;
REAR->NEXT=FRONT;
}
free (TEMP);
return ELE;
}
int ISEMPTY()
{
if (FRONT==NULL)
return 1;
else
return 0;
}
int ISFULL()
{
P=(struct QUEUE *)malloc (sizeof(struct QUEUE));
if (P==NULL)
return 1;
else
return 0;
}
Your's friendly,
[MOHANRAM.G],
ADMIN...
0 comments:
Post a Comment