answersLogoWhite

0

How do you insert the item in queue?

User Avatar

Anonymous

13y ago
Updated: 8/20/2019

# define maxsize 5

int front=-1,rear=-1;

initially set the front=rear=-1

During first insertion, increment front and rear location by counter variable say i

ie front++

rear++

User Avatar

Wiki User

13y ago

What else can I help you with?

Related Questions

What are the difference between ascending priority queue and descending queue?

Ascending priority queue is a collection of items which can be inserted aurbitarly and which can be removed smallest item. Descending priority queue is similar to ascending priority queue but it allows the deletion of the largest item.


Program of implement queues in an array?

//implement priority queue. #include<stdio.h> #include<conio.h> #include<stdlib.h> #define maxsize 10 void insert(); void delet(); void traverse(); int queue[maxsize]; int item,smallest,loc,i; int front=0; int rear=-1; void main() { int choice; char ch; do { printf("\n 1. insert"); printf("\n 2.delete"); printf("\n 3. traverse"); printf("enter ur choice"); scanf("%d",&choice); switch(choice) { case 1: insert(); break; case 2: delet(); break; case 3: traverse(); break; case 4: exit(1); default:printf("\n entered wrong choice"); } printf("\n do u wish to continue(y/n)"); fflush(stdin); scanf("%c",&ch); } while(ch =='Y' ch == 'y'); getch(); } void insert() { if (rear==maxsize) { printf("\n overflow"); exit(0); } else { printf("enter the element"); scanf("%d",&item); rear=rear + 1; queue[rear]=item; } } void delet() { if(front<0) { printf("underflow"); getch(); exit(0); } else { item=queue[front]; for(i=1;i<=rear;i++) if(item>queue[i]) { loc=i; item=queue[i]; //front=front+1; for(loc=i;loc<=rear;loc++) queue[loc]=queue[loc+1]; front=front+1; rear=rear-1; printf("deleted item=%d",item); } } } void traverse() { int i; for(i=front;i<=rear;i++) { printf("%d",queue[i]); } }


What are the various operations that can be performed on a queue?

In queue insertion takes place on rear end and deletion takes place on front end. INSERTION(QUEUE,N,FRONT,REAR,ITEM) :QUEUE is the name of a array on which we are implementing the queue having size N. view comlete ans at http://mcabcanotes.in/algorithm-to-perform-insertion-and-deletion-in-a-queue/


Algorithm to delete elements at both ends in a dequeue?

Delete Front---- DQDELETE_FRONT(QUEUE, FRONT, REAR, ITEM) 1. [check for queue underflow] If FRONT<0, Then: Print: "Queue is empty", and Return. 2. ITEM = QUEUE[FRONT]; 3. Set FRONT = FRONT + 1. 4. Return. Delete Rear---- DQDELETE_REAR(QUEUE, REAR, FRONT, ITEM) 1. [check for queue underflow] If REAR<0, Then: Print: "Queue is empty", and Return. 2. ITEM = QUEUE[REAR]. 3. Set REAR = REAR - 1. 4.Return.


How do you add something to instant queue?

To add an item to an instant queue, you typically need to access the queue management interface of the specific system you are using. Look for an option such as "Add to Queue" or "Enqueue," where you can select the item you want to add. Once selected, confirm the action to place the item in the queue. Make sure to check any specific guidelines or settings related to your queue management system.


Write a program in c language to reverse elements of a queue?

There are many ways to reverse the order of the elements in a queue. Provided that you have access to the implementation of the queue, it is of course easy to read the elements from the tail end rather than the front end, thus reversing the elements. However, considering the queue as a black box, and assuming the queue only allows for its characteristic operations (removal of head element, addition to tail), the best method to reverse the elements in a queue to engage a stack. You'd remove the elements from the queue (always reading the head of the queue), and push each element onto the stack. When the queue is empty, you reverse that process: pop each element from the stack until it is empty, and add each element in this order to the end of the queue. Your queue will have the exact same elements as in the beginning, but in reverse order. The exact implementation of this in C, or in any other programming language, is trivial, but the exact source code depends on the implementation of queue and stack containers. Following is pseudocode: Queue<Item> reverse (Queue<Item> queue) { Stack<Item> stack; Item item; while (queue.remove(&item)) { stack.push(item); } while(stack.pop(&item)) { queue.add(item); } return queue; }


Write down the function to insert an element into a queue, in which the queue is implemented as an array?

bring the police they will be in que by themselves


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.


What do you have to do in a queue?

The queue is a linear data structure where operations od insertion and deletion are performed at separate ends also known as front and rear. Queue is a FIFO structure that is first in first out. Whenever a new item is added to queue, rear pointer is used. and the front pointer is used when an item is deleted from the queue.


Enqueue and dequeue in data structures?

The queue insert operation is known is enqueue. A queue has two ends namely REAR & FRONT. After the data has been inserted in a queue ,the new element becomes REAR.The queue deletion operation is known as dequeue. The data at the front of the queue is removed .


What to Compare and contrast between stack and queue?

A stack is a data structure in which last item inserted is taken out first . That's why they are known as LIFO (last in first out). Inserting an item in stack is termed as push and taking an item out from stack I s termed as pop. Some applications of stack are : Polish notation, reversing string, backtracking , quick sort algorithm etc. The queue is a linear data structure where operations od insertion and deletion are performed at separate ends also known as front and rear. Queue is a FIFO structure that is first in first out. Whenever a new item is added to queue, rear pointer is used. and the front pointer is used when an item is deleted from the queue.


Distinct features of queue and stack?

A stack is a data structure in which last item inserted is taken out first . That's why they are known as LIFO (last in first out). Inserting an item in stack is termed as push and taking an item out from stack I s termed as pop. Some applications of stack are : Polish notation, reversing string, backtracking , quick sort algorithm etc. The queue is a linear data structure where operations od insertion and deletion are performed at separate ends also known as front and rear. Queue is a FIFO structure that is first in first out. Whenever a new item is added to queue, rear pointer is used. and the front pointer is used when an item is deleted from the queue.