Skip to main content

Some useful and known data structure.

Project description

Data Structures for python

  • Linked List
    • Singly Linked List
    • Circularly Singly Linked List
    • Doubly Linked List
    • Circularly Doubly Linked List
  • Stack
    • Stack using list
    • Stack using linked list
  • Queue
    • Queue

Installation

Latest Version : 0.0.6

pip install Gsauce-pyds

License

© 2021 Rajarshi Banerjee

This repository is licensed under the MIT license. See Licence for details.

Link to package

Gsauce-pyds | pypi


How to use?

  • Import the pacakge
from dstructure import *

Singly Linked List

from dstructure import *
L_list= SLL()
  • Insert into linked list
from dstructure import *
L_list= SLL()
L_list.push(1)
L_list.push(2)
L_list.push('word')
L_list.printList()

# Output:
# Head--> 1 --> 2 --> word --> Null

# push(value,index=-1) 
# index = -1 --> insert at the end of the list
# index = 0  --> insert at the beginning
# index = 5  --> insert element at location/index 5

# Note: 0 based index
  • Deletion
L_list.delete()  # this will delete the last element
L_list.delete(0) # will delete the first element
L_list.delete(4) # will delete element at index 4

Note: delete() takes one argument index which is by default set to -1, i.e. delete(index=-1) | -1 means it will delete the element from the end.

  • list.len
print(L_list.len) # will print the length of the linked list
  • Reverse()
L_list.reverse() # will reverse the linked list
# reverse() function returns NONE
  • get_node()
# To extract the data of a specific node
L_list.get_node(i) # to collect the ith node.data 
# returns the data of a specific index.

Circularly singly linked list

Relevant Functions are given below:

push(value,index)
'''Inserts values at given index | Default value of index is set to -1 
which means value will be appended at the end.
Indexing is 0 based.  | returns None'''

pop(index)
'''Default value of the index is set to -1 | returns the data after
deleting the specified node at given index.'''

printList()
'''Prints the entire list'''

#example

l=CircularList([1,2,3,4])
print(l.len) # returns the size of the list
l.printList()
#OUTPUT: 
# 4
# Head--> 1--> 2--> 3--> 4--> Null

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

Gsauce-pyds-0.1.0.tar.gz (7.2 kB view hashes)

Uploaded Source

Built Distribution

Gsauce_pyds-0.1.0-py3-none-any.whl (9.0 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