Queue
A queue is a linear list of elements in which deletions can take place only at one end, called the " front " and insertion can take place only at the other end, called " rear ". The term " front " and " rear " are used in describing a linear list only when it is implemented as a queue.
Queues are also called " first-in first-out " (FIFO) list. Since the first element in a queue will be the first element out of the queue. In other words, the order in which elements enter in a queue is the order in which they leave.
Practical daily life : the people waiting in a line at Railway ticket Counter form a queue, where the first person in a line is the first person to get ticket.
In computer world : In timesharing system, in which programs with the same priority form a queue while waiting to be executed.
Operation on Queue
enqueue : To insert an element into the queue
dequeue : To delete an element from the queue
display : To display the elements of the queue
Representation of Queue using array
The implementation of queue data structure using array is very simple, just define a one dimensional array of specific size and insert or delete the values into that array by using FIFO (First In First Out) principle with the help of variables 'front' and 'rear'.
Algorithm to insert an element in a queue
Initially REAR = -1 and FRONT = -1 which represent that queue is empthy , when the first number is inserted in the queue REAR and FRONT both becomes zero. From the next onward , for any insertion FRONT will not be changed only REAR will be incremented by one for each insertion.
0 Comment to "Queue in data structure"
Post a Comment