def insertBeg(self,data): temp = Node(data) temp.next = self.head self.head = temp if self.head.next == None: self.tail = self.head return self.head
def insertBeg(self, data): temp = Node(data) temp.next = self.head self.head = temp if self.head.next == None: self.tail = self.head return self.head
def insert(self, value): temp = self.head x = Node(value) x.prev = temp self.head = x if self.tail == None: self.tail = x else: temp.next = x
def insert(self,value): temp = self.head x = Node(value) x.prev = temp self.head = x if self.tail == None: self.tail = x else: temp.next = x
def insertAtPos(self, data, pos): temp = Node(data) count = 1 curr = self.head while count < pos - 1: curr = curr.next count += 1 storeNext = curr.next curr.next = temp temp.next = storeNext
def push_back(self, value): newnode = Node(value) temp = self.back newnode.next = temp if self.back == None: self.front = newnode self.back = newnode else: self.back.prev = newnode self.back = newnode
def push_back(self,value): newnode = Node(value) temp = self.back newnode.next = temp if self.back == None: self.front = newnode self.back = newnode else: self.back.prev = newnode self.back = newnode
def insertAtPos(self,data,pos): temp = Node(data) count = 1 curr = self.head while count < pos-1: curr = curr.next count += 1 storeNext=curr.next curr.next = temp temp.next = storeNext
def getBtree(start,end,arr): if start>end: return [None] trees = [] for i in range(start,end+1): getL = getBtree(start,i-1,arr) getR = getBtree(i+1,end,arr) for j in getL: for k in getR: root = Node(arr[i]) root.left = j root.right = k trees.append(root) return trees
def merge(head, mid): if head == None: return mid if mid == None: return head curr = Node() temp = curr while head != None and mid != None: if head.value <= mid.value: temp.next = head head = head.next else: temp.next = mid mid = mid.next temp = temp.next if head == None and mid != None: temp.next = mid else: temp.next = head return curr.next
def insertEnd(self, data): temp = Node(data) temp.next = None self.tail.next = temp self.tail = temp return self.tail
def insertEnd(self,data): temp = Node(data) temp.next = None self.tail.next = temp self.tail = temp return self.tail