An open API service indexing awesome lists of open source software.

https://github.com/jconleyscales/two-dimensional-q

Fixed-capacity circular queue backed by a 2D list with wrap-around indexing (Python).
https://github.com/jconleyscales/two-dimensional-q

circular-buffer data-structures python queue

Last synced: 3 months ago
JSON representation

Fixed-capacity circular queue backed by a 2D list with wrap-around indexing (Python).

Awesome Lists containing this project

README

          

# TwoDimensionalQ (2D Circular Queue) — Python

A fixed-capacity queue backed by a **2D list** that uses **wrap-around indexing** (circular buffer behavior) to avoid shifting elements.

## Features
- Fixed capacity with usage tracking
- Row-major wrap-around indexing across a 2D backing store
- Core operations:
- `enqueue(item)` → `True` if added, `False` if full
- `dequeue()` → removed item, or `None` if empty
- `peek()` → front item without removing it, or `None` if empty
- `list_queue()` → items in queue order

## How to Run
1. Make sure you have Python 3 installed.
2. Run the file:

```bash```
python two_dimensional_q.py
## Example Usage

```python
from two_dimensional_q import TwoDimensionalQ

q = TwoDimensionalQ(2) # capacity = 4
q.enqueue("A")
q.enqueue("B")

print(q.peek()) # A
print(q.dequeue()) # A
print(q.list_queue()) # ['B']