Esempio n. 1
0
 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
Esempio n. 2
0
 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
Esempio n. 3
0
 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
Esempio n. 4
0
 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
Esempio n. 5
0
 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
Esempio n. 6
0
 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
Esempio n. 7
0
 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
Esempio n. 8
0
 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
Esempio n. 9
0
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
Esempio n. 10
0
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
Esempio n. 11
0
 def insertEnd(self, data):
     temp = Node(data)
     temp.next = None
     self.tail.next = temp
     self.tail = temp
     return self.tail
Esempio n. 12
0
 def insertEnd(self,data):
     temp = Node(data)
     temp.next = None
     self.tail.next = temp
     self.tail = temp
     return self.tail