Wiki User
∙ 11y agoThe 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]);
Wiki User
∙ 11y agoWiki User
∙ 11y agomanas sir se pucho;
wahi bata payenge
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.
theory part to how u can insert element at middle of 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.
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
pseudo code algorithm to create a linked list
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.
theory part to how u can insert element at middle of link list ?
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.
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.
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
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.
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
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.
pseudo code algorithm to create 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
Insert, Update, Delete
It is to Edit