answersLogoWhite

0


Best Answer

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]);

User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

manas sir se pucho;

wahi bata payenge

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Algorithm to insert and delete an element from a circular queue?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Difference between simple queue and circular queue?

Simple queue is a linear queue having front & rear var to insert & delete elements from the list.But there is a boundary that we have to insert at rear & have delete from front.For this reason instead of having space in the queue if there is a single element in the rear,the queue is full.the other space is wasted.To utilize space properly,circular queue is derived.In this queue the elements are inserted in circular manner.So that no space is wasted at all.


3 Write the algorithm of inserting an element at middle of a linked?

theory part to how u can insert element at middle of link list ?


Why you use doubly link list?

In a doubly linked list, you can iterate backwards as easily as forwards, as each element contains links to both the prior and the following element. You can also insert or delete an element without needing to iterate and remember the prior element's link. This comes at a cost. You are adding storage to each element for the second link, and you are adding processing overhead to the insert and delete operation. You have to determine the tradeoff.


Write an algorithm to insert an item to a given location in sorted array?

To insert a number N into array A at index I: // Resize A if necessary If A is too small to add a new element then resize A // Right-shift all elements starting from position I For i = A.length to I A[i] = A[i - 1] // Insert new item A[I] = N


What is pseudo code algorithm for create a linked list with a header and insert a four numbers to the list?

pseudo code algorithm to create a linked list

Related questions

Difference between simple queue and circular queue?

Simple queue is a linear queue having front & rear var to insert & delete elements from the list.But there is a boundary that we have to insert at rear & have delete from front.For this reason instead of having space in the queue if there is a single element in the rear,the queue is full.the other space is wasted.To utilize space properly,circular queue is derived.In this queue the elements are inserted in circular manner.So that no space is wasted at all.


3 Write the algorithm of inserting an element at middle of a linked?

theory part to how u can insert element at middle of link list ?


Assuming an emty list what operations are used to delete and insert a data?

Delete is not possible for an empty list, insert is something like this: Create a new list-element. Register it as the first element of the list. Register it as the last element of the list.


What is an algorithm of inserting elements of link list?

To insert an element in a linked list, you need a pointer to the new element, and a pointer to the target element. Set new.next = target.next, and then set target.next = new. This will insert new after target. To insert before target, you need the pointer to the element brfore target, and you can find that by searching from top until you find an element where element.next == target. To insert at top, a special case, you set new.next = top, and then set top = new.


Does binary search tree take much time than the list to delete or insert an element?

No. Binary search tree will take less time to delete or insert an element. While deleting from list, more time will be required to search for the element to be deleted but BST will work faster if the no. of elements are more. Plus it depends upon which element is to be deleted and where the element is to be added. But the average time to perform these operations will be less in BST as compared to lists


Why you use doubly link list?

In a doubly linked list, you can iterate backwards as easily as forwards, as each element contains links to both the prior and the following element. You can also insert or delete an element without needing to iterate and remember the prior element's link. This comes at a cost. You are adding storage to each element for the second link, and you are adding processing overhead to the insert and delete operation. You have to determine the tradeoff.


Write an algorithm to insert an item to a given location in sorted array?

To insert a number N into array A at index I: // Resize A if necessary If A is too small to add a new element then resize A // Right-shift all elements starting from position I For i = A.length to I A[i] = A[i - 1] // Insert new item A[I] = N


Adavantage of pointer based of a list over an array?

One advantage of a linked list (with pointers) is that it is fairly cheap to insert or delete an element - once you know where it is. A disadvantage is that getting a specific element - for example, the 1000th. element - is expensive.


What is pseudo code algorithm for create a linked list with a header and insert a four numbers to the list?

pseudo code algorithm to create a linked list


How to write an actual algorithm for inserting an element in a linked list?

Insert newNode into a linked list after targetNode Node currentNode = root while currentNode != targetNode currentNode = currentNode.next newNode.next = currentNode.next currentNode.next = newNode


What are the database transactions types?

Insert, Update, Delete


To insert delete or replace text is to the document?

It is to Edit