Welcome
Introducing PyDSA - Queue ¶
PyDSA - Queue (pydsa-queue
) is a suite of Python namespaced packages that provides implementations of the Queue ADT and related algorithms.
Two implementations of the Queue ADT are included in the project off the shelf:
-
CircArrayQueue
: Circular array based implementation -
SLListQueue
: Singly linked list based implementation
Different implementations of the Queue ADT are defined in separate modules.
from pydsa.queue import CircArrayQueue
q = CircArrayQueue[int](4, 'int')
print(f"element type: '{q.element_type}'") # ~> "element type: 'int'"
for x in (3, 1, 4, 1, 5):
q.enqueue(x)
print(q) # ~> "[3,1,4,1,5]"
for x in q:
print(f'{x} ', end='')
print() # ~> "3 1 4 1 5"
while not q.empty:
print(f'dequeue: front = {q.front()} | size = {len(q)}')
q.dequeue()
print(q, f'(queue is empty: {q.empty})') # ~> "[] (queue is empty: True)"
from operator import gt
from pydsa.queue import CircArrayQueue
from pydsa.queue.algo import merge
nums1 = (4, 7, 2, 10)
q1 = CircArrayQueue[int](len(nums1), 'int')
for num in nums1:
q1.enqueue(num)
nums2 = (3, 6, 8, 9, 5, 1)
q2 = CircArrayQueue[int](len(nums2), 'int')
for num in nums2:
q2.enqueue(num)
merged = merge(q1, q2, gt)
print(f'merged : {merged}') # ~> "merged : [4,7,3,6,8,9,5,2,10,1]"
Getting Started ¶
Here's what you need to get started.
Dependencies¶
Not much. Python 3.7+ is the only dependency.
Installation¶
Just use pip
.
pip install -U pydsa-queue
License¶
pydsa-queue
is licensed under the BSD 3-Clause License.
Also Want It In Another Language? ¶
- C : Repository | Documentation
- C++ : Repository | Documentation
- Go : Repository | Documentation [coming soon]
- TypeScript : Repository | Documentation