Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gsauc3/gsauce-pyds
Advanced-Data Structures for python
https://github.com/gsauc3/gsauce-pyds
circular-linked-list data-structures doubly-circular-linked-list doubly-linked-list doublylinkedlist linked-list python python-3 python-library queue stack
Last synced: 14 days ago
JSON representation
Advanced-Data Structures for python
- Host: GitHub
- URL: https://github.com/gsauc3/gsauce-pyds
- Owner: GSAUC3
- License: mit
- Created: 2021-09-21T20:45:55.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-05-20T05:21:23.000Z (over 1 year ago)
- Last Synced: 2024-12-22T15:56:32.534Z (14 days ago)
- Topics: circular-linked-list, data-structures, doubly-circular-linked-list, doubly-linked-list, doublylinkedlist, linked-list, python, python-3, python-library, queue, stack
- Language: Python
- Homepage:
- Size: 63.5 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# Data Structures for python
## Installation
Latest Version : 1.0.0
python version needed: `>= 3.9````
pip install Gsauce-pyds
```
# Data Structures Implemented so far
Linked List | Doubly linked list | Stacks | Queue | dequeue## Linked List
```python
from dstructure.linkedlist import LinkedList
l = LinkedList(range(8))
print(l)
# LinkedList([0, 1, 2, 3, 4, 5, 6, 7])l.append('last')
print(l)
# LinkedList([0, 1, 2, 3, 4, 5, 6, 7, last])print(len(l))
#9print(l[0],l[5],l[8])
# Node(data = 0) Node(data = 5) Node(data = last)print(l.head,l.tail)
# Node(data = 0) Node(data = last)l[8]=8
print(l)
# LinkedList([0, 1, 2, 3, 4, 5, 6, 7, 8])l.reverse()
print(l,'head: ',l.head,'tail: ',l.tail,sep='\n')
# LinkedList([8, 7, 6, 5, 4, 3, 2, 1, 0])
# head:
# Node(data = 8)
# tail:
# Node(data = 0)print(l[:3],l[3:])
# LinkedList([8, 7, 6]) LinkedList([5, 4, 3, 2, 1, 0])l.insert(0,'zero')
l.insert(3,'three')
print(l,len(l),l.head,l.tail,sep='\n')
# LinkedList([zero, 8, 7, three, 6, 5, 4, 3, 2, 1, 0])
# 11
# Node(data = zero)
# Node(data = 0)l.remove(0)
l.remove(3)
print(l,l.head,l.tail,sep='\n')
# LinkedList([8, 7, three, 5, 4, 3, 2, 1, 0])
# Node(data = 8)
# Node(data = 0)a = LinkedList('a b c'.split())
print(a)
a + l # concatenation will overwrite the original list, in this case it's a
print(a)
# LinkedList([a, b, c])
# LinkedList([a, b, c, 8, 7, three, 5, 4, 3, 2, 1, 0])print(len(a))
a.pop()
a.pop()
print(len(a))
# 12
# 10
````NOTE: to get the data of any LinkedList and DoublyLinkedList nodes use .data attribute | ex: l.head.data will return the actual value`
## Doubly Linked List```python
from dstructure.linkedlist import DoublyLinkedListl = DoublyLinkedList(range(4))
print(l)
# DLList([0 1 2 3])l.append(4)
print(l,len(l))
# DLList([0 1 2 3 4]) 5l.pop()
print(l)
# DLList([0 1 2 3])print(l.head,l[0],l.tail,l[3],sep='\t')
# Node(data = 0) Node(data = 0) Node(data = 3) Node(data = 3)l.reverse()
print(l.head,l[0],l.tail,l[3],sep='\t')
# Node(data = 3) Node(data = 3) Node(data = 0) Node(data = 0)print(l.head.next,l.tail.prev)
# Node(data = 2) Node(data = 1)print(l)
l[2]='two'
print(l)
# DLList([3 2 1 0])
# DLList([3 2 two 0])print(l[:2],l[2:])
# DLList([3 2]) DLList([two 0])```
## Stack
```python
from dstructure.stack import Stack2s = Stack2(range(3))
print(s,len(s))
# Stack([0,1,2]) 3s.push(3)
s.push(5)
print(s,len(s))
# Stack([0,1,2,3,5]) 5s.pop()
print(s,len(s))
# Stack([0,1,2,3]) 4print(s.peek)
# 3
```## Queue
```python
from dstructure.queues import Queues = Queue(range(4))
print(s,len(s))
# Queue([0,1,2,3]) 4s.enqueue('back')
s.enqueue('to back')
print(s,len(s))
# Queue([0,1,2,3,back,to back]) 6s.dequeue()
print(s,len(s))
# Queue([1,2,3,back,to back]) 5print(s.isempty)
# Falsefor _ in range(len(s)):
s.dequeue()
print(s.isempty,len(s),s)
# True 0 Queue([])
```
## Dequeue
```pythonfrom dstructure.queues import Dequeue
s = Dequeue(range(4))
print(s,len(s))
# Dequeue([0,1,2,3]) 4s.appendback('back')
s.appendfront('front')
print(s,len(s))
# Dequeue([front,0,1,2,3,back]) 6s.popback()
s.popfront()
print(s,len(s))
# Dequeue([0,1,2,3]) 4print(s.isempty)
for _ in range(len(s)):
s.popback()
print(s.isempty,s,len(s))# False
# True Dequeue([]) 0
```## License
© 2021 Rajarshi Banerjee
This repository is licensed under the MIT license. See Licence for details.
## Link to package
***