Exemple #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
Exemple #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
Exemple #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
Exemple #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
Exemple #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
Exemple #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
Exemple #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
Exemple #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
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
Exemple #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
Exemple #11
0
 def insertEnd(self, data):
     temp = Node(data)
     temp.next = None
     self.tail.next = temp
     self.tail = temp
     return self.tail
Exemple #12
0
 def insertEnd(self,data):
     temp = Node(data)
     temp.next = None
     self.tail.next = temp
     self.tail = temp
     return self.tail