Queue (abstract data type)

In computer science, a queue (English queue [ kju ] ) denotes a data structure commonly used.

Principle of operation

A queue can, in contrast to the later-described ring buffer, take an arbitrary set of objects and returns them in the order of their insertion back. These queues provide the operations

  • Enqueue to add an object and
  • Dequeue to retrieve and remove an object

Ready.

  • While the queue ( by law) takes infinitely many objects, the ring buffer at exhaustion, an overflow can occur for a service must be arranged, see also below.

Worked, that is, it is always returned by dequeue the object from the queue, which of the first in the queue still existing objects as this case, after the first in - - First Out principle, short FIFO ( first-in first-out German ) was laid with enqueue.

Illustration

You can think of a queue as a queue of customers at a checkout. The last person who was raised in the snake, is also served as the last. Conversely, one who has been hired as the first, serves first.

Press enter a new value ( 3) of the snake will be added and removed with the saved leave the longest element (37). The only read access is done with front and returns the first element stored in the queue (in this example 37, of course, assuming that the surgery leave not yet been executed ).

Application

The pipe used for inter-process communication is one of the most important applications for queues.

By queues and slow external devices such as printers, of program execution are decoupled. After a print job in the queue setting the program the job is signaled as ' printed ', in fact, the request will be processed later when the device is available.

Queues are also often used for data transfer between asynchronous processes in distributed systems, so if data must be buffered before being further processed. The access is done through enshrined in the operating system APIs. The size of the queue is limited by the operating system.

Graphical user interfaces buffer mouse and keyboard events in a so-called " Message Queue " and then share them, depending on position and input focus, the correct processes to.

A queue can also be used for paralleling. This can be thought of as a post office, in which there are a plurality of switches for a queue. So tasks can be set that are processed later in parallel.

Implementation as a ring buffer

Queues are often implemented as a ring buffer, each with a pointer to the beginning ( In - pointers) and end ( out- pointer). The particularity of the circular buffer is that it has a fixed size. Here, the in- pointer points to the first free element in the array which represents the ring buffer, and the out- pointer to the first element in the finished array. In contrast to the array, the oldest content will be overwritten when the buffer is full and more elements are stored in the ring buffer. An implementation of the ring buffer should be the case that the ring buffer is full, either a buffer overflow signal or provide additional storage space. In other cases, may be intentional overwriting old elements of the queue, and thus the loss of data.

Also, the flight recorder in an airplane is a ring buffer in the rule, so after a crash, only the last few minutes of the recorded measured values ​​are available.

Relationship with stacks (stacks )

Queues can be thought of as a stack of books that are filled from below; accordingly there are implementations that make no difference in principle between stacks and queues. In REXX, the read end of a queue is established; PUSH stored entries are read according to the LIFO principle (Last In - First Out), with QUEUE stored according to the FIFO principle. For inter-process communication cues are of particular interest.

565407
de