queues

Bodhak queues using c tutorial in this chapter we will discuss Queues of Data Structures. The Concepts are explained with programs.

A Queue is a special kind of data structure in which elements are added at one end (called the rear), and elements are removed from the other end (called the front).

 

Queues using c:

Objectives

In this session you will learn to:

Define a Queue

Describe the operations on a queue

Implement a queue as a special case of a linked list

Describe applications of queues

Defining a Queue:

A Queue is a special kind of data structure in which elements are added at one end (called the rear), and elements are removed from the other end (called the front).

You come across a number of examples of a queue in real life situations.

For example, consider a line of students at a fee counter. Whenever a student enters the queue, he stands at the end of the queue (analogous to the addition of nodes to the queue)

Every time the student at the front of the queue deposits the fee, he leaves the queue (analogous to deleting nodes from a queue).

The student who comes first in the queue is the one who leaves the queue first.

Since the first item inserted is the first item removed, a queue is commonly called a first-in-first-out or a FIFO data structure.

Queue Operations:

To complete this definition of a queue, you must specify all the operations that it permits.

The first step you must perform in working with any queue is to initialize the queue for further use. Other important operations are

Add or insert an element into a queue.

Delete an element from a queue.

Display the contents of a queue.

Adding an element is popularly known as ENQ and deleting an element is know as DEQ. The following slide lists operations typically performed on a queue.

Applications of Queues:

Queues are also very useful in a time-sharing multi-user operating system where many users share the CPU simultaneously.

Whenever a user requests the CPU to run a particular program, the operating system adds the request ( by first of all converting the program into a process that is a running instance of the program, and assigning the process an ID).

This process ID is then added at the end of the queue of jobs waiting to be executed.

Whenever the CPU is free, it executes the job that is at the front of the job queue.

Similarly, there are queues for shared I/O devices. Each device maintains its own queue of requests.

An example is a print queue on a network printer, which queues up print jobs issued by various users on the network.

The first print request is the first one to be processed. New print requests are added at the end of the queue.

queues using c