Skip to main content

Sophisticate Linked Stack

Project description

lstack

PyPI version License: MIT

This library was created to make the stack concept easier to understand by visualizing it and showing how objects enter and exit the stack, especially for beginners in data structures

Installation

You can install lstack via pip:

pip install lstack

Usage

For singlyLinkedStack

from lstack import singlyLinkedStack

x = singlyLinkedStack(capacity=7)
print(x)

Output

[]

You Can Visualize The Stack With All Details

from lstack import singlyLinkedStack

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

Output

╒════════════╕
│ ENTER  ^   │
│   |    |   │
│   v   EXIT │
├────────────┤
├────────────┤
├────────────┤
├────────────┤
├────────────┤
├────────────┤
├────────────┤
╘════════════╛

Push

from lstack import singlyLinkedStack

x = singlyLinkedStack(capacity=7, detail=True)
print(x)
x.push(1)
x.push(2)
x.push(3)
print(x)

Output

╒════════════╕
│ ENTER  ^   │
│   |    |   │
│   v   EXIT │
├────────────┤
├────────────┤
├────────────┤
├────────────┤
├────────────┤
├────────────┤
├────────────┤
╘════════════╛
╒════════════╕
│ ENTER  ^   │
│   |    |   │
│   v   EXIT │
├────────────┤
├────────────┤
├────────────┤
├────────────┤
├────────────┤
│ 3          │
├────────────┤
│ 2          │
├────────────┤
│ 1          │
╘════════════╛

Pop

from lstack import singlyLinkedStack

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

Output

╒════════════╕
│ ENTER  ^   │
│   |    |   │
│   v   EXIT │
├────────────┤
├────────────┤
├────────────┤
├────────────┤
├────────────┤
│ 3          │
├────────────┤
│ 2          │
├────────────┤
│ 1          │
╘════════════╛
╒════════════╕
│ ENTER  ^   │
│   |    |   │
│   v   EXIT │
├────────────┤
├────────────┤
├────────────┤
├────────────┤
├────────────┤
├────────────┤
│ 2          │
├────────────┤
│ 1          │
╘════════════╛

You Can Check If The Stack Is Empty Or Not

from lstack import singlyLinkedStack

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

Output

True

You Can Check If The Stack Is Full Or Not

from lstack import singlyLinkedStack

x = singlyLinkedStack([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 Stack Using peek Or top

from lstack import singlyLinkedStack

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

Output

7
7

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

from lstack import singlyLinkedStack

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

Output

3

You Can Clear The Stack

from lstack import singlyLinkedStack

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

Output

╒════════════╕
│ ENTER  ^   │
│   |    |   │
│   v   EXIT │
├────────────┤
├────────────┤
├────────────┤
├────────────┤
├────────────┤
│ 7          │
├────────────┤
│ 6          │
├────────────┤
│ 5          │
╘════════════╛
╒════════════╕
│ ENTER  ^   │
│   |    |   │
│   v   EXIT │
├────────────┤
├────────────┤
├────────────┤
├────────────┤
├────────────┤
├────────────┤
├────────────┤
╘════════════╛

Note

You can use doublyLinkedStack with the same syntax as singlyLinkedStack with all previous methods the main difference is singlyLinkedStack use static non circular singly linked list and doublyLinkedStack use static non circular doubly 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

lstack-1.1.0.tar.gz (4.4 kB view hashes)

Uploaded Source

Built Distribution

lstack-1.1.0-py3-none-any.whl (4.4 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