def set(self,index,element): newNode = LinkedListNode(element) if(index>0): prevNode = self.get(index-1) newNode.next = prevNode.next.next prevNode.next = newNode prevNode.next.next = None
def insert(self,index,element): newNode = LinkedListNode(element) if(index==0): self.push_front(newNode) else: prevNode = self.get(index-1) newNode.next = prevNode.next prevNode.next = newNode return newNode
def insert(self, data): """ Insert the data to front list. Returns True if the data was added, False otherwise. """ curr = Node(data) if self.size == 0: self.head = curr self.size += 1 return True curr.next = self.head self.head = curr self.size += 1 return True
def push_front(self,element): newRoot = LinkedListNode(element) oldRoot = self.root self.root = newRoot newRoot.next = oldRoot