Method to add an element in circular queue, Data Structure & Algorithms

Q. Let us consider a queue is housed in an array in circular fashion or trend. It is required to add new items to the queue. Write down a method ENQ to achieve this also check whether the queue is full. Write down another procedure DQ to delete an element after checking queue empty status.  


The Method To Add an element in Circular Queue

# define  MAXQUEUE 100 struct queue{

int items[MAXQUEUE];

int front, rear;


struct queue q;

q.front=q.rear=MAXQUEUE -1;

void ENQ(struct queue *pq, int x)


/* make room for new element*/

if(pq ->rear = MAXQUEUE - 1)

pq-> rear = 0;



/* check for overflow */

if(pq ->rear==pq->front)


printf("queue overflow);





}/* end of ENQ*/

A Method to Delete an element from Circular Queue

int DQ(struct queue *pq)


if(pq-> rear == pq-> front)


printf("queue underflow");


}/*end if*/

if(pq->front = = MAXQUEUE-1)





}/*end DQ*/

Posted Date: 7/12/2012 9:16:50 AM | Location : United States

Related Discussions:- Method to add an element in circular queue, Assignment Help, Ask Question on Method to add an element in circular queue, Get Answer, Expert's Help, Method to add an element in circular queue Discussions

Write discussion on Method to add an element in circular queue
Your posts are moderated
Related Questions

Q. Write down an algorithm to evaluate an expression given to you in postfix notation. Show the execution of your algorithm for the following given expression. AB^CD-EF/GH+/+*

Circular Queues:- A more efficient queue representation is get by regarding the array Q(1:n) as circular. It becomes more convenient to declare the array as Q(O: n-1), when  re

Consider a linked list of n elements. What is the time taken to insert an element after an element pointed by some pointer? O (1)

Implement algorithm to solve 5-1 fifth order equation given.

Insertion & deletion of target key requires splaying of the tree. In case of insertion, the tree is splayed to find the target. If, target key is found out, then we have a duplicat

Q. Explain the insertion sort with a proper algorithm. What is the complication of insertion sort in the worst case?

difference between recursion and iteration

Definition: A set of data values & related operations that are accurately specified independent of any particular implementation. As the data values and operations are described