linked-list

Linked list implementation in python issue

Linked list implementation in python issue Question: I have been trying to implement a linked-list in python.Any call of a variable inside a function in Python is by default call by reference.I have this code: For the list_node: class list_node: def __init__(self,obj,next_listnode): self.obj = obj self.next_listnode = next_listnode For the linked_list: class linked_list: def __init__(self,list_node): …

Total answers: 1

Linked list problem (Leetcode) – understanding inputs

Linked list problem (Leetcode) – understanding inputs Question: I am starting to complete some Leetcode problems, having finished an online Data Structures and Algorithms course, but I’m struggling to understand what some of the input variables represent. I’ve included one of the solutions as an example. The problem gives me the head of a sorted …

Total answers: 1

Linked List, can't acess the data from NEXT NODE

Linked List, can't acess the data from NEXT NODE Question: My problem is at the display function, I can’t access the value cur_node.data which is a reference to node.next.data. I’m new to python and I’m trying to learn Linked LISTS, this code is from an old VIDEO which is why it probably isn’t working My …

Total answers: 1

how to count the nodes in a linked list?

how to count the nodes in a linked list? Question: this is my code but im not being able to count the nodes in the list, ive also given the test cases below those test cases should get executed class LinkedList: def __init__(self, a): self.head = None tail=None list=[] for x in a: if x …

Total answers: 1

What does "aggregated" mean in this context? aggregated=False? (Python)

What does "aggregated" mean in this context? aggregated=False? (Python) Question: Looking over assignments and practice we were working with Linked Lists and we were provided with the following code : ` class LinkedList: class ListNode: def __init__(self, data=None): self.next = None self.prev = None self.data = data def __init__(self): self.first = None self.last = None …

Total answers: 1

Linked List Recursive Value Sum

Linked List Recursive Value Sum Question: I am trying to recursively determine the sum of the values in a linked list. I am aware of one recursive solution that works: def sum_list_rec1(head_node: Node): if head_node == None: return 0 return head_node.value + sum_list_rec1(head_node.next) However, I am trying to use the pattern where a variable is …

Total answers: 2

Attribute Error: 'NoneType' object has no attribute '_next'

Attribute Error: 'NoneType' object has no attribute '_next' Question: I understand that these errors occur when plugging instance methods or any preset functions to None type, but since I’m implementing a singly Linked List I need to assign a None type to the last node. How do I resolve this issue since I can’t change …

Total answers: 2

Graph – Adjacency List solved as Linked List

Graph – Adjacency List solved as Linked List Question: What does this line do? node.next = self.graph[src] EX: [1:2] here I know how to make 2 as a node, then make index 1 equal it, but what if i have [1:3] too, how to add 3 to 2? Here’s the full code of Adjacency List …

Total answers: 1

Merge Two Sorted Lists Python

Merge Two Sorted Lists Python Question: I’m trying to solve merge sorted linked list problem.For that i’ve created three method. addlast , print and merge For linked list class created a three objects obj and obj1 (To create two linked list) Using obj3 calling a merge method by passing both linked list head pointer.But here …

Total answers: 3