## DEV Community

Aya Bouchiha

Posted on • Updated on

# Queue Data Structure

Hi, today, we're going to discuss queue :)

## Definition Of Queue

A Queue is a linear data structure that stores items in a First-In/First-Out (FIFO) manner. In Queue, the element that goes in first is the element that comes out first.

## Space and Time complexity

the space complexity of a queue is O(n)

add ( enqueue ) remove (dequeue) search access
O(1) O(1) O(n) O(n)

## Implementation of queue using python

``````class Queue:

def __init__(self,size):
self.items = []
self.front = self.rear = 0
self.size = size
``````

### Enqueue

``````def enqueue(self,data):
if not self.isFull()  :
self.items.append(data)
self.rear += 1
else:
return 'full'
``````

### Dequeue

``````def dequeue(self):
if not self.isEmpty() :
self.items.pop(0)
self.rear -= 1
return 'deleted successfuly'
return 'empty'
``````

### isEmpty

``````    def isEmpty(self) -> bool:
return  self.rear == self.front
``````

### isFull

``````    def isFull(self) -> bool :
return self.size == self.rear
``````

#day_3
Have a good day!