Monday, December 26, 2016

Implementation of Queue Data Structure using Python


Today i will be implementing Queue Data Structure using Python.

Before we will go to Coding , lets try to understand what is Queue data structure.

Queue Data StructuresQueue is also an abstract data type or a linear data structure , in which the first element is inserted from one end called REAR(also called tail), and the deletion of existing element takes place from the other end called as FRONT(also called head).So it works on FIFO principle.



One may ask what is importance of queue and where it can be used.?
Queue is a data structure . One of the practical example we can take to understand the same is the way  printers are used.
Assume we have printer in shared network, so everybody send there request for printing.
So it should print for the request which came first.

Lets try to implement the same via Python .


So i have created a class with name Queue .

On creation of object of this class , will create array que which will hold our data.

The method Enqueue will add element to this array.
The Dequeue will remove the element from position zero , so which means the element which has been added first will  be removed and this process will go subsequently.

The other methods which i have implemented is isEmpty() and find() , which is to check if the queue is empty or not not.
While find will check if the data exist in our queue or not.  




No comments:

Post a Comment