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.


This content originally appeared on DEV Community and was authored by Aya Bouchiha

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.

queue data structure

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 
            return f'{self.items[-1]} added'
        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

References and useful ressources

#day_3
Have a good day!


This content originally appeared on DEV Community and was authored by Aya Bouchiha


Print Share Comment Cite Upload Translate Updates
APA

Aya Bouchiha | Sciencx (2021-06-15T18:56:10+00:00) Queue Data Structure. Retrieved from https://www.scien.cx/2021/06/15/queue-data-structure/

MLA
" » Queue Data Structure." Aya Bouchiha | Sciencx - Tuesday June 15, 2021, https://www.scien.cx/2021/06/15/queue-data-structure/
HARVARD
Aya Bouchiha | Sciencx Tuesday June 15, 2021 » Queue Data Structure., viewed ,<https://www.scien.cx/2021/06/15/queue-data-structure/>
VANCOUVER
Aya Bouchiha | Sciencx - » Queue Data Structure. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/06/15/queue-data-structure/
CHICAGO
" » Queue Data Structure." Aya Bouchiha | Sciencx - Accessed . https://www.scien.cx/2021/06/15/queue-data-structure/
IEEE
" » Queue Data Structure." Aya Bouchiha | Sciencx [Online]. Available: https://www.scien.cx/2021/06/15/queue-data-structure/. [Accessed: ]
rf:citation
» Queue Data Structure | Aya Bouchiha | Sciencx | https://www.scien.cx/2021/06/15/queue-data-structure/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.