Skip to main content

Data Structure

Project description

Dstructure

Dstructure is a Python library for dealing with data struture and algorithms.

Installation

Use the package manager pip to install dstructure.

pip install dstructure

Usage

1.Singly Linked List

Singly linked list. Singly linked lists contain nodes which have a data field as well as 'next' field, which points to the next node in line of nodes. Operations that can be performed on singly linked lists include insertion, deletion and traversal.

from dstructure.SLL import SLL

obj=SLL() 
obj.insert(10) # insert 10 in linked list
obj.insert(20) # insert 20 in linked list
obj.insert(30) # insert 30 in linked list
obj.insert(40) # insert 40 in linked list
obj.delete_f() # delete first node in linked list
obj.delete_l() # delete last node in linked list
obj.delete(20) # delete the node which we pass and return True otherwise False
obj.getnodes() # return all the node in linked list in list.
obj.print()	   # print all the in this format 10 -> 30 -> 40

2.Doubly Linked List

Doubly linked list is a type of linked list in which each node apart from storing its data has two links. The first link points to the previous node in the list and the second link points to the next node in the list.

from dstructure.DLL import DLL

obj=DLL() 
obj.insert(10) # insert 10 in linked list
obj.insert(20) # insert 20 in linked list
obj.insert(30) # insert 30 in linked list
obj.insert(40) # insert 40 in linked list
obj.delete_f() # delete first node in linked list
obj.delete_l() # delete last node in linked list
obj.delete(20) # delete the node which we pass and return True otherwise False
obj.getnodes() # return all the node in linked list in list.
obj.print()	   # print all the in this format 10 <-> 30 <-> 40

3.Singly Circular Linked List

In a singly linked list, for accessing any node of linked list, we start traversing from the first node. If we are at any node in the middle of the list, then it is not possible to access nodes that precede the given node. This problem can be solved by slightly altering the structure of singly linked list. In a singly linked list, next part (pointer to next node) is NULL, if we utilize this link to point to the first node then we can reach preceding nodes.

from dstructure.SCLL import SCLL

obj=SCLL() 
obj.insert(10) # insert 10 in linked list
obj.insert(20) # insert 20 in linked list
obj.insert(30) # insert 30 in linked list
obj.insert(40) # insert 40 in linked list
obj.delete_f() # delete first node in linked list
obj.delete_l() # delete last node in linked list
obj.delete(20) # delete the node which we pass and return True otherwise False
obj.getnodes() # return all the node in linked list in list.
obj.print()	   # print all the in this format 10 -> 30 -> 40

4.Doubly Circular Linked List

Circular Doubly Linked List has properties of both doubly linked list and circular linked list in which two consecutive elements are linked or connected by previous and next pointer and the last node points to first node by next pointer and also the first node points to last node by previous pointer.

from dstructure.DCLL import DCLL

obj=DCLL() 
obj.insert(10) # insert 10 in linked list
obj.insert(20) # insert 20 in linked list
obj.insert(30) # insert 30 in linked list
obj.insert(40) # insert 40 in linked list
obj.delete_f() # delete first node in linked list
obj.delete_l() # delete last node in linked list
obj.delete(20) # delete the node which we pass and return True otherwise False
obj.getnodes() # return all the node in linked list in list.
obj.print()	   # print all the in this format 10 <-> 30 <-> 40

5.Binary Tree

A binary tree is a hierarchical data structure in which each node has at most two children generally referred as left child and right child. Each node contains three components: Pointer to left subtree. Pointer to right subtree. Data element.

from dstructure.BTree import BTree

obj=BTree(23) 
obj.insert(10) # insert 10 in linked list
obj.insert(20) # insert 20 in linked list
obj.insert(30) # insert 30 in linked list
obj.insert(40) # insert 40 in linked list
obj.getnodes() # return all the node in linked list in list
obj.inorder()  # return inorder in list
obj.preorder() # return preorder in list
obj.postorder()# return postorder in list

6.Graph

A graph is a pictorial representation of a set of objects where some pairs of objects are connected by links. The interconnected objects are represented by points termed as vertices, and the links that connect the vertices are called edges.

from dstructure.Graph import Graph

a=Graph()
a.insert(0,1) # insert 0,1 in graph
a.insert(0,3) # insert 0,3 in graph
a.insert(1,2) # insert 1,2 in graph
a.insert(1,3) # insert 1,3 in graph
a.insert(2,3) # insert 2,3 in graph
a.insert(2,4) # insert 2,4 in graph
a.insert(3,4) # insert 3,4 in graph
a.show()     # print all graph
print(a.get_elements())   
print(a.get_vertices())  # get all the vertices
print(a.get_bfs(1))	 # breadth first search

7.HashMap

Hash tables are a type of data structure in which the address or the index value of the data element is generated from a hash function. That makes accessing the data faster as the index value behaves as a key for the data value. In other words Hash table stores key-value pairs but the key is generated through a hashing function.

from dstructure.HashMap import HashMap
obj=HashMap(size) #size of array
obj.set_hash(10) # insert 10 in hashmap using value%size.
obj.search(10) # search in hashmap using value%size.
obj.ascii_hash(30) # insert 30 in hashmap by adding ascii values of all characters.
obj.ascii_search(30) # search 30 in hashmap by adding ascii values of all characters.
obj.print() # print hashmap

Contributing

For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

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

dstructure-0.0.3.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

dstructure-0.0.3-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file dstructure-0.0.3.tar.gz.

File metadata

  • Download URL: dstructure-0.0.3.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.5

File hashes

Hashes for dstructure-0.0.3.tar.gz
Algorithm Hash digest
SHA256 ea69762fecfb1bee77ca1aaac0510982e103b852fc4ada8f097e144a4b376f1d
MD5 d91f424e62340ffadcfaa63edc8c7290
BLAKE2b-256 45ec5ae6a1f64805eaf4f7b23ac6f0f4aac0000f0c4916b162e3a09a067393dc

See more details on using hashes here.

File details

Details for the file dstructure-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: dstructure-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.5

File hashes

Hashes for dstructure-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 079b85bba19a25688e674e4913d2fe4c356d96dda886aa206ffd8c9746e9357d
MD5 0e4d83df97cb85d2af34a16506542c17
BLAKE2b-256 65cef879dd4e7a7bf27616aba2d34160a4882fd40595853164e310590eea5c55

See more details on using hashes here.

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