answersLogoWhite

0

What is queue in c plus plus?

Updated: 8/11/2023
User Avatar

Wiki User

11y ago

Best Answer

A queue is a FIFO data structure. The best way to implement this is to use two pointers, one to track the head and one to track the tail. During a push operation, the tail pointer will advance one spot as the data is entered into the list. During a pop operation, the head pointer will advance one spot as data is removed. When the two pointers are pointing to the same space, the queue is empty.

User Avatar

Wiki User

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

Wiki User

11y ago

A queue is a singly linked list that models a first in first out model (just as a queue of diners are dealt with on a first come first served basis). Insertions always occur at the tail of the queue and extractions always at the head.

A variation of the queue is a priority queue where nodes are weighted such that those with higher priority are moved in front of those with lower priority. This is akin to diners who have a reservation being moved to the head of the queue. In this case, insertions always occur at the head but the head node will pass the data onto the next node if the data has lower priority. The process continues until the data has higher priority than the current node at which point is it is placed in front of the current node. If the current node has no next node to pass the data onto, the data becomes the tail node. This is known as an insertion sort.

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

Arrays are not suitable for implementing queues because extraction occurs at the front of queue while insertions occur at the end of a queue. To avoid shunting elements forward after each extraction you must keep track of the first and last "active" elements in the structure, and only shunt forward when an insertion would result in the need to increase the size of the array, which should only be done when all elements are active. Since these operations are time-consuming and require a certain amount of redundancy, a singly-linked list is the preferred structure for a queue. To avoid traversing the entire list in order to locate the end of the queue (since only the head of the list is directly accessible), the list needs to maintain one additional node pointer for the tail of the list. When inserting a new node, the tail node simply points to the new node and the new node becomes the tail. To extract a node, the node that follows the head becomes the new head. The only other thing to check for is that when the head node is NULL, the tail node must also be NULL (meaning the queue is empty, the initial state).

Singly-linked lists can also be used to implement stacks, where the head node represents the top of the stack, and all insertions and extractions occur at the head of the list.

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

A queue is a first in, first out (FIFO) or last in, last out (LILO) structure, typically implemented via a singly-linked list that maintains pointers to both the head (for extractions) and the tail (for insertions).

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

There's no built-in queue type in C, but you can implement any type you want.

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

last in first out

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is queue in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Array implementation of priority queue example program in c plus plus?

yes


A program for queue ADT by using arrays in c plus plus?

Arrays are not suitable for implementing queues because while they are ideal for adding to the end, the are not ideal for extraction from the beginning. For that you need a deque. Regardless, the STL (standard template library) already provides an efficient queue ADT in std::queue.


Has C got a built-in queue library?

No.


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; }


How do you simulate mouse clicks in c plus plus?

The easy way is to simply invoke the relevant message handlers. If you wish to simulate mouse clicks within another application, however, post the relevant messages to the operating system's message queue. The OS will pass them to the appropriate application.

Related questions

Array implementation of priority queue example program in c plus plus?

yes


A program for queue ADT by using arrays in c plus plus?

Arrays are not suitable for implementing queues because while they are ideal for adding to the end, the are not ideal for extraction from the beginning. For that you need a deque. Regardless, the STL (standard template library) already provides an efficient queue ADT in std::queue.


Has C got a built-in queue library?

No.


How do you detect mouse click globally in C plus plus?

Since most modern operating systems are event-driven you'd need to hook into the system message queue in order to intercept mouse-clicks globally.


List out atleast 5 real life instances where queue and circular queue operations are being used?

A>People will stand on queue for getting a film tickets. B>In Airport the luggage will be flowing in a queue manner. C>Children will walk into the school in queue. D>Getting into the temple we have to stand in a queue. E>School children will do the prayer with a proper queue.


How does the round robin algorithm work?

There is a Queue of processes that need to work on and each process has it's time requirement to complete,eg:process processor timeA 3B 8C 6D 4if the processor give 1 processor time to each process , then A->B->C->D will run each taking 1 processor time and complete a cycle and each process that is not complete will add to the end of the queue, if a process is completed it will remove from the queue(not enqueueing).This process will continue until all the process are completed and the queue is empty.Above que will work as follows.A->B->C->D->A->B->C->D->A->B->C->D>B->C->D->B->C->B->C->B->B-> Que is emptyin each highlighted position process that complete their process time remove from the queue and therefore the rest are processing according to queue.


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; }


What is b plus b plus b plus c plus c plus c plus c?

b+b+b+c+c+c+c =3b+4c


What is c plus c plus 2c plus c plus c equal?

c + c + 2c + c + c = 6c


B plus b plus b plus c plus c plus c plus c equals?

b + b + b + c + c + c + c = 3b + 4c


Symplify c plus c plus c plus c?

4c


What is the program of breadth first search in c plus plus?

The algorithm for breadth first search is to start at the root node or at an arbitrary node within the tree. First, push this node onto a queue. Then proceed as follows 1. If the queue is empty, quit the search and return a "not found" result. 2. Pop the first node from the queue. 3. If this node contains the value you seek, quit the search and return the node. 4. Enumerate the child nodes (if any), and push them onto the queue. 5. Go to step 1.