-->
Search here and hit enter....

Queue Data Structure | Part 6 | IDA using C

  Hello Viewer! how are you? I hope you are very well. Today I have learned about Queue Data Structure. below I have written whatever I learn today ...


queue


QUEUES

A Queue is also a Linear Data Structure because in this DS data is also stored in sequential order.

A Queue is a First-In, First-Out(FIFO) data structure in which the element that is inserted first is the first one to be taken out.

The elements in a queue are added at the end called "Rear" and removed from the other end called "Front".

Like Stack, Queues can be implemented using either Arrays or Linked Lists.


Every Queue has a "Front" and "Rear" variable that points to the position from where insertion and deletion can be done.

adding element to queue


Here, front = 0 and rear = 3 and if we want to add one more value to the list, Suppose

  •  If we want to add another value 19 then the "Rear" would be incremented by 1 and the value will be stored at the position pointed by the "Rear".  [ The queue after adding new element shown in fig(5) ]
Array representation of queue


Now If we want to delete an element from the queue, then the value of "Front" will be incremented.
  • Deletion are done only from this end of the queue. the queue after deletion will be shown in fig(6)

deletion in queue



However, before inserting an element in the Queue, we must check for "Overflow" conditions.

An "Overflow" occurs when we try to insert an element in the Queue that is already full.

A Queue is full when "REAR = MAX - 1", where MAX is the size of the Queue i.e MAX specifies the maximum number elements in the Queue.

Similarly, before deleting an element from the Queue, we must check for "Underflow" conditions.

An Underflow occurs when we try to delete an element from a Queue that is already empty.

A Queue is empty when "FRONT = NULL" and " REAR = NULL" then there is no element in the Queue.


Note:-
A queue has three operations:-
  • enqueue: insert a data item into the queue.
  • dequeue: removes the first data item from it.
  • front: accesses and serves the first data item in the queue.

That's All for Today! I hope You like and understand whatever I have written. If you find any error don't forget to mention it in the comment section or mail me. 💗💗

Note:- I learned this from "Data Structure using C" Book written By Reema Thareja.

FB COMMENTS ()