Skip to content
This repository was archived by the owner on Sep 22, 2024. It is now read-only.

Secrus/PyStack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

PyStack

PyStack is my implementation of stack data structure using Python 3 and mypy.

Code

This project is actually 2 files of source code. node.py is simple data node used by Stack in stack.py.

Example usage

Usage of this code is very simple. You just declare your Stack and its type. Here is example using int type:

stack = Stack[int]()

You can also pass some initial arguments to put on stack at initialization.

stack = Stack[int](12, 13, 14)

NOTE: if you want to pass Python list as arguments, use spread operator with it

stack = Stack[int](*[12, 13, 14])

API

Stack class has very simple and (for those who know what stack data structure is) intuitive API. It offers methods like:

.push(data)
.pop()
.is_empty()
.get_state()

.push(data)

This method adds new data to stack. data param is of a type of your Stack.

.pop()

This methods removes data from top of stack and returns it. If your Stack is empty, it will return None.

.is_empty()

This method returns bool stating whether there is any data on stack (False) or stack is empty (True)

.get_state()

This method returns list of data on stack. Data is of a type of your Stack.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages