Skip to content
Advertisement

Tag: linked-list

Adding a Prepend Method to a Linked List Class

I am currently working on a class project involving linked lists and python. Currently, I am trying to create a prepend function for said linked list. My current code is throwing a recursion error. Here is my code: Node definition: Here is the List function w/ append and broken prepend function: The recursion error occurs at line 29 which is

Build tree/linked list from a list of Objects

I am trying to build a tree like hierarchy from modules and their respective submodules, each module has a name, data, and a list of its submodules, With this code I’m able to detect if something is a submodule of something else but I don’t know how I am supposed to form the connections/build the data structure. My desired output

Insert an item at the begining of linked list by Python3

How to modify the following code? so that the item can be inserted to the begining of a linked list with add()? why None shows up at the beginning of the linked list? is there anything wrong? I tried several times. It just does not work. What heppened? Any suggestions to change? Is ther any good suggestion when writing a

Space complexity in shallow vs deep copy

Consider the problem of merging two sorted linked lists whilst keeping the order. For instance if L1: 1->1->2->4 and L2: 2->3->5 Then the result should be 1->1->2->2->3->4->5. In Elements of Programming Interview, the author presents the following solution in Java, which consists of running through both lists and choosing the smallest value to add to a dummy head: The author

Python comma assignments order [closed]

Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 1 year ago. Improve this question I was trying Python comma assignment to parallelly change the values of variables. I believe Python will evaluate the values of the expressions on the

Reverse a Doubly Linked List is going in a Infinite Loop

The function Reversedll is going into infinite loop here Can anyone help me identify the cause for it????? Program Details : The given function reverseDLL(), which takes head reference as argument and should reverse the elements so that the tail becomes the new head and all pointers are correctly pointed. You need to return the new head of the reversed

Wrong Implementation of LinkedList

I am having trouble with the following code segment. I can’t really figure out why it doesn’t work, any help is appreciated. It’s a very very simple mistake that I do not understand: Prints 5 and it keeps printing 5 if you write u.next.next.next.val, what I want is u.val = 5 , u.next.val = 1 and u.next.next = None Answer

Reversing a linked list(Iterative method)

I am writing a code for reversing a linked list in python. The following code does not pass the test case: while this code passes: What is the difference between the two? Answer In your unrolled code, by the time you get to the last line, curr.next has been overwritten with prev. It no longer has its original value. Both

Advertisement