Skip to content

This repository contains a simple implementation of the Stack data structure in Python, showcasing the classic LIFO (Last In, First Out) behavior.

License

Notifications You must be signed in to change notification settings

Ahmedhm1/Stack-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Stack in Python

This project implements a Stack (LIFO - Last In, First Out) in Python with basic operations:

  • Push values
  • Pop values
  • Check if the stack is empty (is_empty)
  • Get the top value (get_top)
  • Get stack size (len(stack))
  • String representation of the stack

🐍 1. Basic Usage (easiest way)

If you just want to try the stack without installing anything, copy stack.py into the same folder as your project and use:

from stack import Stack

s = Stack()
s.push(1)
s.push(2)
s.push(3)
print(s.get_top())  # 3
print(len(s))       # 3

📦 2. Advanced Usage (install as a package)

If you want to use this as a Python package, you first need Git installed.
👉 Download Git if you don’t already have it.

Then install directly from GitHub using pip:

pip install git+https://github.com/Ahmedhm1/Stack-python.git

Now you can import it anywhere:

from stk import Stack

s = Stack()
s.push(10)
s.push(20)
print(s.get_top())  # 20

🔎 Example Usage

from stk import Stack

s = Stack()

# Push values
s.push(5)
s.push(8)
s.push(12)

# Pop a value
s.pop()  # removes 12

# Get top value
print(s.get_top())  # 8

# Check if empty
print(s.is_empty())  # False

# Print stack
print(s)

📂 Project Structure

Stack-python/
│
├── stk/            # Package source code
│   ├── __init__.py   # Exports Stack
│   └── stack.py      # Stack implementation
│
├── README.md
├── pyproject.toml    # modern build file
└── setup.py          # Package setup script

📖 Source Code

➡️ View stack.py directly if you just want to read the implementation.

About

This repository contains a simple implementation of the Stack data structure in Python, showcasing the classic LIFO (Last In, First Out) behavior.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages