New Tutorials:   KOTLIN    JAVASCRIPT    SASS/SCSS    PL/SQL  
CLOSE
   Data Structures  Python  Stack  
   Technology    Programming

Implementing Stack in Python

         
 MARCH 3, 2020   by HIMANI56

We all know about Stack data structure, right? For those of you who do not know, Stack is a data structure which is used to store data in a structured way.

In a Stack, data which is stored at the end, is the data which is removed first. This is behavious of Stack is also known as Last in First Out or First in Last Out.

A stack data structure generally has the following 3 methods:

  1. push(): For adding data to the stack.

  2. pop(): For removing data from the stack.

  3. size(): To check the size of stack.

  4. isEmpty(): To check if the stack is empty or not.

A few other points to remember are:

  1. You cannot add or remove data randomly from a Stack.

  2. The addition and removal of data elements happen from a single side.

So let's write a simple class Stack to implement stack in python.


RELATED POSTS



Subscribe and receive amazing posts directly in your inbox.