We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Delete a Node
Delete a Node
+ 0 comments def deleteNode(llist, position): if llist==None: return None else: pre=llist count=1 while pre.next is not None and count
+ 0 comments Python
def deleteNode(llist, position): if position == 0: llist = llist.next else:
count = 1 temp = llist while temp != None and count < position: temp = temp.next count += 1# print(temp.data) temp.next = temp.next.next # print(temp.data) return llist
+ 0 comments simple and descritive python solution
def deleteNode(llist: SinglyLinkedListNode, position: int): if llist == None: return if position == 0: return llist.next position_counter: int = 0 current: SinglyLinkedListNode = llist while current != None and position_counter < position - 1: position_counter += 1 current = current.next current.next = current.next.next return llist
+ 0 comments def deleteNode(head, position): if position == 0: head = head.next else: temp = head count = 1 while temp != None and count < position: temp = temp.next count += 1 temp.next = temp.next.next return head
+ 0 comments Python
def deleteNode(llist, position): if position == 0: llist = llist.next else: previous = llist for _ in range(position - 1): previous = previous.next to_delete = previous.next following = to_delete.next previous.next = following del to_delete return llist
Load more conversations
Sort 743 Discussions, By:
Please Login in order to post a comment