Linear Queue : Data Structure and Algorithm

Linear Queues

A queue is an ordered list in which items may be added only at one end called the "rear" and items may be removed only at the other end called "front". 

Linear Queues

A line of passengers waiting to buy tickets at a reservation counter. Each new passenger gets in line at the "rear", the passenger at the front of the lines is reserved.

A linear queue can be found in a time-sharing computer system where many users share the system simultaneously.

The first element, which is added into the queue will be the first one to be removed. Thus queues are also called First-In-First-Out lists (FIFO) or Last-In-Last-Out(LILO)

linear queue example

  • Queues may be represented in the computer memory by means of linear arrays or linked lists.
  • There are two pointer variables namely FRONT and REAR.
  • The FRONT denotes the location of the first element of the queue.
  • The rear describes the location of the rear element of the queue.
  • When the queue is empty, the values of the front and rear are -1 and -1 respectively.
  • The "max-size" represents the maximum capacity of the linear queue.
  • The following is the condition to test the queue is full or not. (REAR == max size -1)
  • To insert the first element both pointers should be altered to "0" Front = 0 rear =0.
  • Whenever an item is added to the queue, the value of REAR is incremented by 1. REAR = REAR + 1;
  • The following is the condition to test the queue is empty or not.FRONT ==-1.
  • Whenever an "item " is deleted from the queue, the value if the front is incremented by 1 FRONT = FRONT +1;
  • TO delete the last element, both pointers should be altered.


Views

Post a Comment

0 Comments