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.  

Ans.

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;

else

(pq->rear)++;

/* check for overflow */

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

{

printf("queue overflow);

exit(1);

}

pq->items[pq->rear]=x;

return;

}/* 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");

exit(1);

}/*end if*/

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

pq->front=0;

else

(pq->front)++;

return(pq->items[pq->front]);

}/*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
Data array A has data series from 1,000,000 to 1 with step size 1, which is in perfect decreasing order. Data array B has data series from 1 to 1,000,000, which is in random order.

How to create an General Tree and how to search general tree?

The simplest implementation of the Dijkstra's algorithm stores vertices of set Q into an ordinary linked list or array, and operation Extract-Min(Q) is just a linear search through

Example of Area Subdivision Method The procedure will be explained with respect to an illustrative problem, with the image consisting of five objects, namely a triangle (T), qu

what do we use asymptotic notation in study of algorithm?Describe various asymptotic notation and give their significance.

Q. Prove the hypothesis that "A tree having 'm' nodes has exactly (m-1) branches".      Ans: A tree having m number of nodes has exactly (m-1) branches Proof: A root

Technique for direct search is    Hashing is the used for direct search.

draw a flowchart which prints all the even numbers between 1-50

algorithm for multiplication of two sparse matrices using linked lists..

Hubs - In reality a multiport repeater - Connects stations in a physical star topology - As well may create multiple levels of hierarchy to remove length limitation of 10