I’ve tried this: class Node: def __init__(self, initdata): self.data = initdata self.next = None class LinkedList: def __init__(self): self.head = None self.tail = None def add(self, data): new_node = Node(data) if self.head == None: self.head = new_node if self.tail != None: self.tail.next = new_node self.tail = new_node def reverseList(self): if self.head == None or self.head.next ..

#### Category : linked-list

I have a very basic question about linked list say I reverse the following linked list: #1->2->3->4 to become 4->3->2->1 And say I start first with reversing the pointer that points from 1 to 2; so that 2 points to 1. My question is, does the pointer/connection from 1 to 2 still exist when I ..

(In split function) I ran it without these conditions, and it worked just as same as with them. When we get to a single node linked list, the stopping condition of merge_sort function should just return the same single node linked list back and rest can go on. I saw this in a tutorial and ..

sorry for beginner question here. I’m trying to implement an insert method for a linked list class, using recursion, as seen in the code below. However, when I try it, I get back a list that infinitely repeats the value I want to insert. e.g. 1st node is ‘a’, 2nd node is ‘b’, 3rd node ..

From list first I should do LinkedList and put elements into it (I did that). From that list I have to move all not string elements (integers) to another LinkedList and print them also. Initialisation: class Node: def __init__(self, data): self.data = data self.next = None class LinkedList(object): def __init__(self): self.head = None self.tail = ..

I have found a recursive solution to check whether a linked list is a palindrome: def isPalindrome(self, head: ListNode) -> bool: self.front_pointer = head def recursively_check(head): if head: if not recursively_check(head.next): return False if self.front_pointer.val != head.val: return False self.front_pointer = self.front_pointer.next return True return recursively_check() After the ‘if head’ statement: Why are we returning ..

I have a class named Poly that takes in a list of tuples and converts them into polynomials… now I’m running into some issues in my addition function and can’t figure out how to get all info into my string. Current Output Based on Input: >>> i = [(2,3),(2,1),(3,4)] >>> f = [(2,3),(3,1)] >>> p ..

i watched a video and copied the code. i want to know for certain that this is a linked list and not something else. sorry if this is a bad question. i dont know where to ask this. no hate plz "A banana is an elongated, edible fruit – botanically a berry[1][2] – produced by ..

In this class Polynomial takes in a list of tuples like such >> [(1,2),(3,1),(2,3),(2,2)] What I need to do for this specific part is take in a list of tuples and then the insert function and init functions should be able to organize the data in ascending order based on exponents by creating nodes in ..

I am reversing a singly- linked list with the following code: class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next class Solution: def reverseList(self, head: ListNode) -> ListNode: if not head: return [] curr = head.next prev = head while curr: curr.next = prev curr = curr.next prev = prev.next return curr ..

## Recent Comments