Skip to main content

Sophisticate Circular Queue

Project description

cqueue

PyPI version License: MIT

This library was created to make the concept of a queue easier by visualizing it and showing how items enter and exit it, especially for beginners in data structures

Installation

You can install cqueue via pip:

pip install cqueue

Usage

For Circular Queue

from cqueue import circularQueue

x = circularQueue(capacity=7)
print(x)

Output

[]

You Can Visualize The Queue With All Details

from cqueue import circularQueue

x = circularQueue(capacity=7, detail=True)
print(x)

Output

╒═════════╤══╤══╤══╤══╤══╤══╤══╤══════════╕
│ <- EXIT                <- ENTER │
╘═════════╧══╧══╧══╧══╧══╧══╧══╧══════════╛

Enqueue

from cqueue import circularQueue

x = circularQueue(capacity=7, detail=True)
print(x)
x.enqueue(1)
x.enqueue(2)
x.enqueue(3)
print(x)

Output

╒═════════╤══╤══╤══╤══╤══╤══╤══╤══════════╕
│ <- EXIT                <- ENTER │
╘═════════╧══╧══╧══╧══╧══╧══╧══╧══════════╛
╒═════════╤═══╤═══╤═══╤══╤══╤══╤══╤══════════╕
│ <- EXIT  1  2  3          <- ENTER │
╘═════════╧═══╧═══╧═══╧══╧══╧══╧══╧══════════╛

Dequeue

from cqueue import circularQueue

x = circularQueue([1, 2, 3], capacity=7, detail=True)
print(x)
x.dequeue()
print(x)

Output

╒═════════╤═══╤═══╤═══╤══╤══╤══╤══╤══════════╕
│ <- EXIT  1  2  3          <- ENTER │
╘═════════╧═══╧═══╧═══╧══╧══╧══╧══╧══════════╛
╒═════════╤═══╤═══╤══╤══╤══╤══╤══╤══════════╕
│ <- EXIT  2  3            <- ENTER │
╘═════════╧═══╧═══╧══╧══╧══╧══╧══╧══════════╛

You Can Check If The Queue Is Empty Or Not

from cqueue import circularQueue

x = circularQueue(capacity=7, detail=True)
print(x.isEmpty())

Output

True

You Can Check If The Queue Is Full Or Not

from cqueue import circularQueue

x = circularQueue([1, 2, 3, 4, 5, 6, 7], capacity=7, detail=True)
print(x.isFull())

Output

True

You Can See The Item Who Can EXIT From The Queue Using peek Or top

from cqueue import circularQueue

x = circularQueue([5, 6, 7], capacity=7, detail=True)
print(x.peek())
print(x.top())

Output

5
5

You Can See How Many Items Are In The Queue Using len Function

from cqueue import circularQueue

x = circularQueue([5, 6, 7], capacity=7, detail=True)
print(len(x))

Output

3

You Can Clear The Queue

from cqueue import circularQueue

x = circularQueue([5, 6, 7], capacity=7, detail=True)
print(x)
x.clear()
print(x)

Output

╒═════════╤═══╤═══╤═══╤══╤══╤══╤══╤══════════╕
│ <- EXIT  5  6  7          <- ENTER │
╘═════════╧═══╧═══╧═══╧══╧══╧══╧══╧══════════╛
╒═════════╤══╤══╤══╤══╤══╤══╤══╤══════════╕
│ <- EXIT                <- ENTER │
╘═════════╧══╧══╧══╧══╧══╧══╧══╧══════════╛

For Linked Circular Queue

You can use linkedCircularQueue with the same syntax as circularQueue with all previous methods the main difference is circularQueue use static array(list) and linkedCircularQueue use static circular singly linked list

License

This project is licensed under the MIT LICENSE - see the LICENSE for more details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cqueue-1.0.5.tar.gz (4.5 kB view hashes)

Uploaded Source

Built Distribution

cqueue-1.0.5-py3-none-any.whl (4.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page