Package: dstructure
dstructuredstructure is a Python library for dealing with data struture and algorithms.InstallationUse the package managerpipto install dstructure.pipinstalldstructureUsage1.Singly Linked ListSingly 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.fromdstructure.SLLimportSLLobj=SLL()obj.insert(10)# insert 10 in linked listobj.insert(20)# insert 20 in linked listobj.insert(30)# insert 30 in linked listobj.insert(40)# insert 40 in linked listobj.delete_f()# delete first node in linked listobj.delete_l()# delete last node in linked listobj.delete(20)# delete the node which we pass and return True otherwise Falseobj.getnodes()# return all the node in linked list in list.obj.print()# print all the in this format 10 -> 30 -> 402.Doubly Linked ListDoubly 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.fromdstructure.DLLimportDLLobj=DLL()obj.insert(10)# insert 10 in linked listobj.insert(20)# insert 20 in linked listobj.insert(30)# insert 30 in linked listobj.insert(40)# insert 40 in linked listobj.delete_f()# delete first node in linked listobj.delete_l()# delete last node in linked listobj.delete(20)# delete the node which we pass and return True otherwise Falseobj.getnodes()# return all the node in linked list in list.obj.print()# print all the in this format 10 <-> 30 <-> 403.Singly Circular Linked ListIn 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.fromdstructure.SCLLimportSCLLobj=SCLL()obj.insert(10)# insert 10 in linked listobj.insert(20)# insert 20 in linked listobj.insert(30)# insert 30 in linked listobj.insert(40)# insert 40 in linked listobj.delete_f()# delete first node in linked listobj.delete_l()# delete last node in linked listobj.delete(20)# delete the node which we pass and return True otherwise Falseobj.getnodes()# return all the node in linked list in list.obj.print()# print all the in this format 10 -> 30 -> 404.Doubly Circular Linked ListCircular 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.fromdstructure.DCLLimportDCLLobj=DCLL()obj.insert(10)# insert 10 in linked listobj.insert(20)# insert 20 in linked listobj.insert(30)# insert 30 in linked listobj.insert(40)# insert 40 in linked listobj.delete_f()# delete first node in linked listobj.delete_l()# delete last node in linked listobj.delete(20)# delete the node which we pass and return True otherwise Falseobj.getnodes()# return all the node in linked list in list.obj.print()# print all the in this format 10 <-> 30 <-> 405.Binary TreeA 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.fromdstructure.BTreeimportBTreeobj=BTree(23)obj.insert(10)# insert 10 in linked listobj.insert(20)# insert 20 in linked listobj.insert(30)# insert 30 in linked listobj.insert(40)# insert 40 in linked listobj.getnodes()# return all the node in linked list in listobj.inorder()# return inorder in listobj.preorder()# return preorder in listobj.postorder()# return postorder in list6.GraphA 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.fromdstructure.GraphimportGrapha=Graph()a.insert(0,1)# insert 0,1 in grapha.insert(0,3)# insert 0,3 in grapha.insert(1,2)# insert 1,2 in grapha.insert(1,3)# insert 1,3 in grapha.insert(2,3)# insert 2,3 in grapha.insert(2,4)# insert 2,4 in grapha.insert(3,4)# insert 3,4 in grapha.show()# print all graphprint(a.get_elements())print(a.get_vertices())# get all the verticesprint(a.get_bfs(1))# breadth first search7.HashMapHash 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.fromdstructure.HashMapimportHashMapobj=HashMap(size)#size of arrayobj.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 hashmap8.MinHeapA Min-Heap is a complete binary tree in which the value in each internal node is smaller than or equal to the values in the children of that node. Mapping the elements of a heap into an array is trivial: if a node is stored a index k, then its left child is stored at index 2k + 1 and its right child at index 2k + 2.fromdstructure.MinHeapimportMinHeapobj=MinHeap([5,4,1,3,2])#Create the object of heap and pass the array.obj.make_heap()# This function make the heaptop=obj.top()# This function return the min element which on the top.obj.push(30)# insert the element into heap.obj.pop()# pop function delete the first element from heap.print(obj)# print heap9.MaxHeapA max-heap is a complete binary tree in which the value in each internal node is greater than or equal to the values in the children of that node. Mapping the elements of a heap into an array is trivial: if a node is stored an index k, then its left child is stored at index 2k+1 and its right child at index 2k+2.fromdstructure.MinHeapimportMinHeapobj=MinHeap([5,4,1,3,2])#Create the object of heap and pass the array.obj.make_heap()# This function make the heaptop=obj.top()# This function return the max element which on the top.obj.push(30)# insert the element into heap.obj.pop()# pop function delete the first element from heap.print(obj)# print heapContributingFor major changes, please open an issue first to discuss what you would like to change.Please make sure to update tests as appropriate.LicenseMIT