Skip to main content

All Questions

1 vote
2 answers
105 views

I don't understand how this function works, which is reverse() function in implementation of a linked list

Here is code for implementing a singly-linked list: class LinkedList { constructor(value) { this.head = { value: value, next: null, }; this.tail = this.head; this.length =...
AbdelrahmanMurad's user avatar
1 vote
2 answers
131 views

Why I'm hitting time limit!? LeetCode Linked List Cycle (Solved but explanation needed!)

I'm working on solving LeetCode problem 141. Linked List Cycle: Given head, the head of a linked list, determine if the linked list has a cycle in it. There is a cycle in a linked list if there is ...
Simone Anthony's user avatar
1 vote
0 answers
56 views

Singly Linked list partial traversal. Before node that references the dummy node is different than it at the end. How is this possible

Below I have some code to implement a singly linked list which implements the following Given the head of a singly linked list and two integers left and right where left <= right, reverse the ...
Luke's user avatar
  • 1,850
1 vote
1 answer
114 views

I'm trying to reverse a linked list but I'm confused about how the last node works?

I'm trying to reverse a singly linked list in JavaScript recursively. I already know the solution, but I need some clarification. Here is my code: var reverseList = function(head) { var reverse = ...
dslash's user avatar
  • 11
0 votes
1 answer
232 views

Space Complexity of Linked List by using pointer

I have declared a class Node for creating new node in linked list like this: class Node{ constructor(data){ this.data = data; this.next = null; } } Then I tried to iterate through the ...
Harshdeep Singh's user avatar
0 votes
2 answers
82 views

How does push method work on head Node in SinglyLinkedList

I can't wrap my head around how does Head also changes whenever assigning a new Node to Tail. Do I miss something important about how Class works? Please explain in detail to me. class Node { ...
Jim Chang's user avatar
0 votes
1 answer
1k views

Inserting element into specific index in a Linked List (Javascript)

I cannot figure out why my code isn't working and I've been staring at it forever. When I try to call the function, I get the error "Cannot read properties of null (reading 'next')" and ...
clowniecat's user avatar
0 votes
0 answers
22 views

Console.log() logs the output before passing a argument in a method of a class [duplicate]

The code below is a PUSH method of singly linked list in javascript which adds a element to the tail value in the list. How come the 1st output shows the linked list before passing the argument inside ...
Ankit Singh's user avatar
1 vote
2 answers
188 views

Unable to convert class syntax to function syntax for a Linked List

Okay so I'm learning Data Structures where my tutorial is following class syntax. So now I am trying to convert it to function declarations as I want to practice Linked Lists with that notation. Can ...
s.khan's user avatar
  • 415
0 votes
1 answer
477 views

I'm trying to answer Hackeranks data structure question and i don't know why this function fails

This is the question and my solution in Javascript You are given the pointer to the head node of a linked list and an integer to add to the list. Create a new node with the given integer. Insert this ...
lovelyn marshall's user avatar
7 votes
2 answers
2k views

LinkedList push() method in JavaScript with a tail

I try to understand how push() method works with the use of tails in JS. here is the code: class Node { constructor(val) { this.val = val; this.next = null; } } class ...
Elchin's user avatar
  • 105
0 votes
1 answer
107 views

How do I recursively reverse a linked list?

Input: 5 -> 9 -> 8 -> 3 -> 1 -> 7 Expected Output: 7 -> 1 -> 3 -> 8 -> 9 -> 5 Issue: When I display the reversed linked list the result is 5. This is an issue because this should be the tail and ...
peyo's user avatar
  • 371
1 vote
1 answer
246 views

Why is my queue data-structure in javascript behaving the way it shouldn't

I have implemented a queue using linked list. I added a enqueue and dequeue function. As per the data structure, if after using dequeue, the item after 'front' item should become front but my code is ...
Ajay Jarhad's user avatar
1 vote
1 answer
42 views

Having trouble understanding the logic of this while loop

I'm practicing singly-linked list and I'm having trouble understanding the logic of one section of the provided example code. Here is the entire code: function Node(data) { this.data = data; ...
Allan's user avatar
  • 43
1 vote
2 answers
2k views

data structure association list - how to create head key value pairs?

I have a question about a data structure association list / a singly-linked list which only adds to the head. The set function is suppose to set (multiple) key-value pairs and the get function should ...
javascript2016's user avatar