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
A graph G might be defined as a finite set V of vertices & a set E of edges (pair of connected vertices). The notation utilized is as follows: Graph G = (V, E) Consider the g

Using the cohen sutherland. Algorithm. Find the visible portion of the line P(40,80) Q(120,30) inside the window is defined as ABCD A(20,20),B(60,20),C(60,40)and D(20,40)

Explain about Hidden-surface Hidden-line removal refers to wire-frame diagrams without surface rendering and polygonal surfaces with straight edges. Hidden-surface removal ref

Merge sort is a sorting algorithm which uses the basic idea of divide and conquers. This algorithm initially divides the array into two halves, sorts them separately and then merge

Write an algorithm for binary search. What are its limitations? .

The disadvantages or limitations of the last in first out costing method are: The election of last in first out for income tax purposes is binding for all subsequent yea

. Create a decision table that describes the movement of inventory

The data structure needed to evaluate a postfix expression is  Stack

Explain Optimal Binary Search Trees One of the principal application of Binary Search Tree is to execute the operation of searching. If probabilities of searching for elements

In this unit, we will describe a data structure called Graph. Actually, graph is a general tree along no parent-child relationship. In computer science, Graphs have several applica