Stacks and Queues

Learn how stack and queues work in Python.

This lesson lists different implementations of stack and queue provided by Python 3 and explains when to use which built-in support.

Introduction

A stack is a data structure that follows the LIFO (Last In First Out) order for push (insertion) and pop (deletion) functions.

A queue is a data structure that follows the FIFO (First In First Out) order for enqueue (insertion) and dequeue (deletion) functions.

Stack
Stack
Queue
Queue

Stack and queue implementation

Using list

As you know, list is one of the basic built-in data structures in Python. It allows random access in O(1) ...

Access this course and 1400+ top-rated courses and projects.