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

Assignment Help:

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*/


Related Discussions:- Method to add an element in circular queue

Calculus, basic calculation for algorith.

basic calculation for algorith.

What is a container taxonomy, What is A Container Taxonomy It's useful ...

What is A Container Taxonomy It's useful to place containers in a taxonomy to help understand their relationships to one another and as a basis for implementation using a class

Explain b- tree, B- Tree  A B-tree of order m is an m-way true in which...

B- Tree  A B-tree of order m is an m-way true in which  1)  All leaves are on the similar level 2)  All internal nodes except the root have at most m-1(non-empty) childre

Find a minimum cost spanning arborescence rooted, Find a minimum cost spann...

Find a minimum cost spanning arborescence rooted at r for the digraph shown below, using the final algorithm shown in class. Please show your work, and also give a final diagram wh

What is algorithms optimality, What is algorithm's Optimality? Optimali...

What is algorithm's Optimality? Optimality  is  about  the  complexity  of  the  problem  that  algorithm  solves.  What  is  the  minimum amount  of  effort  any  algorithm  w

Implementation of a binary tree, Like general tree, binary trees are implem...

Like general tree, binary trees are implemented through linked lists. A typical node in a Binary tree has a structure as follows struct NODE { struct NODE *leftchild; i

Graph & optimal scheduling, You are given an undirected graph G = (V, E) in...

You are given an undirected graph G = (V, E) in which the edge weights are highly restricted. In particular, each edge has a positive integer weight of either {1,2,...,W}, where W

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd