Implementing Queue Data Structure In Python

Implementing Queue Data Structure In Python

Instructor-svgAl-Mamun Sarkar
Mar 28 , 2020

Implementing queue In Python. The queue is a data structure that follows First In Frist Out. The following code shows how to implement a queue data structure in the Python programming language. 

Code:

class Queue:
    def __init__(self):
        self.queue = []

    def enqueue(self, data):
        self.queue.insert(0, data)

    def dequeue(self):
        return self.queue.pop()

    def main(self):
        self.enqueue('One Data')
        self.enqueue('Two Data')
        self.enqueue('Three Data')
        print('Start Popping')
        print(self.dequeue())
        print(self.queue)


if __name__ == '__main__':
    queue_obj = Queue()
    queue_obj.main()

 

Output:

Start Popping
One Data
['Three Data', 'Two Data']

 

  • Share On:
  • fb
  • twitter
  • pinterest
  • instagram