Skip to main content

All Questions

0 votes
1 answer
173 views

My method for eliminating the largest sequence of repeated elements on singly linked list does not work

This code is supposed to search through a Node list for the largest sequence of repeated elements and then eliminate it (each Node has connection only to the next element, it is a singly linked list). ...
Raúl Armas's user avatar
0 votes
1 answer
663 views

How to remove the nth node from the end of the list reversing the linked-list?

I want to remove the nth node from the end of the list by reversing the linked list first and then removing the nth node. I know there's a better solution than this, but the way I'm thinking is like ...
Mo Fatah's user avatar
  • 169
1 vote
2 answers
232 views

Function not returning anything when it should be returning int

So I've got this function that is supposed to take an Optional[Node] as a parameter. The Node class is recursive, and takes in data: int and next: Optional[Node] as parameters. The idea of my function ...
mesunmoon's user avatar
0 votes
1 answer
176 views

Python class attribute can't use its own object

I'm new to python and writing two classes to define a singly linkedlist object. I'm having a problem with my _Node class. For the 'next' attribute of the _Node class, I want to set its type to be ...
Kai Li's user avatar
  • 55
-1 votes
2 answers
1k views

How to add 2 singly-linked lists together?

I am trying to write a Python function that adds two linked lists together. Each node contains one digit of a potentially large integer, with the least-significant digit coming first Ex Function: ...
Droem19's user avatar
  • 59
1 vote
0 answers
48 views

How can we remove a node in a LinkedList given only a pointer to the node AFTER it?

This is similar to the classic interview question of removing a middle node from a LinkedList given only a pointer to that node. Now, what if you were only given a pointer to the node that comes AFTER ...
Peter's user avatar
  • 31
-1 votes
2 answers
575 views

How does a node with return self work?(Python)

So this is the node part of a singly linked list. I am not supposed to change the way it has been coded, but I dont know how this type of structure would work. Self.link cannot event be accessed to ...
hxalchemy's user avatar
  • 374
0 votes
1 answer
45 views

How do I update my self.tail in a method for deleting a node at a specific position when the position is the last node?

Method obtained from googling and changed a bit: def removeNodeAtPosition(self, position): if self.head == None: print("List is empty") return current = self.head if ...
QuNova's user avatar
  • 1
0 votes
0 answers
832 views

How do I assign two or more values to a single node in a singly linked list in python?

I wanted to create a singly linked list with two values a node as practice after having successfully done it with one value per node, though I have no idea how exactly to approach this. I've tried to ...
QuNova's user avatar
  • 1
1 vote
2 answers
1k views

Singly Linked List with special methods in python, stuck

A singly linked list with two classes, Node and LinkedList, is easy enough to implement. however my issue is when it comes to a singly linked list with only first node access (No stored length, No ...
DJXiej's user avatar
  • 48