def insert(self, pos, item): assert pos <= self.get_size(), "Error in insert: position exceed limit" current = self.__head previous = None temp = d_linked_node(item, None, None) if (self.__head == None): self.__head = temp self.__tail = temp else: # find position to add item i = 0 while i != pos: previous = current current = current.getNext() i += 1 if previous == None: self.__head = temp else: previous.setNext(temp) temp.setPrevious(previous) if current == None: self.__tail = temp else: temp.setNext(current) current.setPrevious(temp) self.__size += 1
def append(self, item): if self.__size == 0: self.add(item) else: self.__size +=1 temp = d_linked_node(item,None,self.__tail) self.__tail.setNext(temp) self.__tail = temp
def append(self, item): temp = d_linked_node(item, None, None) if self.__size == 0: self.__head = temp else: self.__tail.setNext(temp) temp.setPrevious(self.__tail) self.__tail = temp self.__size += 1
def add(self, item): temp = d_linked_node(item,self.__head,None) temp.setNext(self.__head) if self.__head != None: self.__head.setPrevious(temp) else: self.__tail = temp self.__head = temp self.__size += 1
def add(self, item): # add item to beginning of list (index 0) temp = d_linked_node(item, self.__head, None) if self.__head != None: # if list is not empty self.__head.setPrevious(temp) # add temp to front else: # if list is empty, head is also the tail self.__tail = temp self.__head = temp # new item is head cuz we're adding to front self.__size += 1
def append(self, item): a = d_linked_node(item, None, None) if self.__tail == None: self.__tail = a self.__head = a else: self.__tail.setNext(a) a.setPrevious( self.__tail ) self.__tail = a self.__size += 1
def append(self, item): temp = d_linked_node(item, None, None) if self.__head == None: self.__head == temp else: current = self.__head while (current.getNext() != None): currten = current.getNext() current.setNext(temp) self.__size += 1
def append(self, item): # adds item to the end of list temp = d_linked_node(item, None, None) if (self.__head == None): self.__head = temp else: self.__tail.setNext(temp) temp.setPrevious(self.__tail) self.__tail = temp self.__size += 1
def add(self, item): temp = d_linked_node(item,None,None) if (self.__tail == None): self.__head = temp self.__size += 1 self.__tail = temp else: temp.setNext(self.__head) self.__head.setPrevious(temp) self.__head = temp self.__size += 1
def add(self, item): temp = d_linked_node(item, None, None) if self.__m_sorted: if self.__size == 0: self.__items.add(item) else: pos = self.__items.search_larger(item) #print(item, pos) if pos == -1: self.__items.append(item) elif pos == 0: self.__items.add(item) else: self.__items.insert(pos, item) self.__size += 1 else: self.__items.append(item) self.__size += 1
def insert(self, pos, item): s = 0; if pos > self.__size - 1 : raise Exception ("size to big") if pos == 0: self.add(item) elif pos == self.__size : self.append(item) else: cu = self.__head while cu: if s == pos: pre = cu.getPrevious() a = d_linked_node(item, cu, pre) pre.setNext(a) cu.setPrevious(a) self.__size += 1 break else: cu = cu.getNext() s += 1
def insert(self, pos, item): # TODO: s = 0 if pos > self.__size - 1: raise Exception("size to big") if pos == 0: self.add(item) elif pos == self.__size: self.append(item) else: current = self.__head while current: if s == pos: pre = current.getPrevious() a = d_linked_node(item, current, pre) pre.setNext(a) current.setPrevious(a) self.__size += 1 break else: current = current.getNext() s += 1
def insert(self, pos, item): if pos > self.__size: raise Exception('Index out of range!') temp = d_linked_node(item, None, None) current = self.__head previous = None for i in range(pos): previous = current current = current.getNext() if previous == None: self.__head = temp temp.setPrevious(None) temp.setNext(current) current.setPrevious(temp) elif current == None: temp.setPrevious(previous) previous.setNext(temp) self.__tail = temp else: temp.setNext(current) temp.setPrevious(previous) previous.setNext(temp) current.setPrevious(temp) self.__size += 1
def insert(self, pos, item): temp = self.__head temp_in = d_linked_node(item,None,None) for i in range(pos): temp = temp.getNext() if (pos == 0): temp_in.setNext(self.__head) self.__head = temp_in if (self.__size == 0): self.__tail = temp_in else: temp_in.getNext().setPrevious(temp_in) self.__size +=1 else: if (temp == None): temp_in.setPrevious(self.__tail) self.__tail.setNext(temp_in) self.__tail=temp_in else: temp_in.setNext(temp) temp.getPrevious().setNext(temp_in) temp_in.setPrevious(temp.getPrevious()) temp.setPrevious(temp_in) self.__size +=1
def add(self, item): temp = d_linked_node(item, None, None) temp.setNext(self.__head) self.__head = temp self.__size = self.__size + 1