In: Computer Science
What is BCP? When does it used?
Queue is a data structure which follows FIFO that is
First-In-First-Out pattern where both its ends are open and one end
is used for insert data and other is used to delete data.Queue
could be implemented using Arrays, linked-lists and in case we want
to keep it simple then opt one dimensional array.
Now let us see different operations that could be performed on
queue, enqueue(used to add an item to the queue), dequeue(used to
delete an item from the queue), peek(it is used to fetch the
element at front of the queue without removing that item),
isfull(is used to check whether the queue if full or not),
isempty(used to check whether the queue is empty).Now let us see
the two basic and major functions of queue:
1) Enqueue : As mentioned this is used to add item to the queue,
queue maintains two pointers rear and front which points to data
and out of which rear is used to point at the end of the queue to
insert data.
a) Check if queue is full.
b) If queue is not full then the rear pointer is moved to point to
the next available space.
c) Then add the item at the index where rear is pointing to.
2) Dequeue : As mentioned dequeue is used to delete data from
queue and as deletion is done from front of the queue , front
pointer is used.
a) First we need to check if queue is empty.
b) If not empty, then fetch the data where currently front is
pointing.
c) And then increment the front pointer to point to next available
item.