Python code for Merge Sort, Doubly Linked List and Binary Tree
9 Pages1107 Words290 Views
Added on 2019-10-18
About This Document
The code includes implementation of Merge Sort, Doubly Linked List and Binary Tree in Python. Merge Sort is used to sort the given array. Doubly Linked List is used to insert and remove elements from the list. Binary Tree is used to find the minimum value in the tree.
Python code for Merge Sort, Doubly Linked List and Binary Tree
class Node(object): def __init__(self, value): self.value=value self.next=None self.prev=Noneclass List(object): def __init__(self): self.head=None self.tail=None def insert(self,n,x): #Not actually perfect: how do we prepend to an existing list? if n!=None: x.next=n.next n.next=x x.prev=n if x.next!=None: x.next.prev=x if self.head==None: self.head=self.tail=x x.prev=x.next=None elif self.tail==n: self.tail=x def remove(self, val): """Remove a node from the list.""" current = self.head
End of preview
Want to access all the pages? Upload your documents or become a member.