Coders Packet

Building stack using linked list in Python

By Patnam Venkata Koushik

Implementing various functions of a stack using the singly linked list class in Python

Stack is one of the most prominent and important data structure. It is a linear data structure which follows a particular order while performing any function on the stack. It either follows First in Last out(FILO) or Last in First out(LIFO). In this project, we have implemented the stack data structure with the help of linked list. The following are the functions that are defined and can be performed on a stack.

  1. Constructor:

This function is used to initialise the data members.

  1. push(data) :

This function is used to push data into the stack. It takes one integer input from the user and then the function will push this value into the stack and return nothing.

  1. pop() :

This function pops the element of the stack from the top of the stack and returns the element being popped or deleted. In case if the stack is empty, it returns -1.

  1. top :

This function gives the value or element that is being kept at the top of the stack. In case if the stack is empty, it returns -1.

  1. size() :

This function gives the size of the stack at any given instance of time.

  1. isEmpty() :

This function gives a boolean value indicating whether the stack is empty or not.


Download Complete Code


No comments yet