VehiclesFashionRecipesBlogsHuntTravelsSportFunHandmadeITEducation
Mini-Games
x

x
zakruti.com » IT - Software » freeCodeCamp.org
Linked List - Beau teaches JavaScript

Linked List - Beau teaches JavaScript

FBTwitterReddit

video description

Rating: 4.0; Vote: 1
A linked list is a common data structure where elements are stored in a node. Learn about linked lists and how to implement them in JavaScript. - Code: https://codepen.io/beaucarnes/pen/ybOvBq?editors=0011 - Info: https://medium.freecodecamp.com/a-gentle-introduction-to-data-structures-how-linked-lists-work-5adc793897dd - Beau Carnes on
Date: 2022-03-14

Comments and reviews: 10


Thanks for your work. But how actually we save the next link to object. Is it reference or object? For example if I have 5 elements in a list and want get first element, I get in google console whole bunch of nesting object from the start to end. If javascript don't have a truly reference type like a C++ or Java maybe we should keep our data in array. What do you think about it? I actually don't know the method that get size in memory of object so I can't imagine how to test list. Also I think if you give es2015 syntax it would be more eye catching.
reply

Seems like you're returning the last element for -this.elementAt- function when we are passing the index greater than its size.
I guess this.elementAt function needs to be corrected with the below code:
this.elementAt = function (index) --
var currentNode = head;-
var count = 0;-
while (count < index) --
count++;-
if (currentNode.next) --
currentNode = currentNode.next;-
- else --
return -Element not found-;-
--
--
return currentNode.element;-
-;

reply

Its just like Relay race, the head is the first runner who will pass the relay stick or (this.next) or NULL stick to the second runner , mind it that the second , third runner.....will be called (currentNode) the last runner is an exception which will be called the tail and it will be the last to hold the NULL stick , otherwise we want to add more runner .
reply

Thank you, I really like this. I like your codepen Linked List; I can go look at it, try to interpret what it does, and then come back and listen to your explanation. n.b. I realise your .add() method adds the new element to the end of the list, whereas you have a .addAt() method to insert a node at any other position of the list.
reply

i don't feel like you need to check all element before add new one, what if you have last element object so when you add new element you just add lastPoint.next = node and then update lastPoint = node like so:
this.lastPoint.next = node
this.lastPoint = node;
and for first time lastPoint = this.head

reply

Great Video! There are some edge cases where this implementation would fail. Example: this.remove() length should only be decremented if the element is found. length-- should either be moved to both the if and else clause, or use some kind of flag set to true if it succeeds. Thanks
reply

It says linked list has efficient insertions and deletions but I don't really get why. Isn't insertion/deletion normally O(n), and only if we're specifically inserting / deleting the head node it's O(1)? I might just be confused, also thanks for the great video.
reply

this guy is good but it makes it hard for me to understand fully if this thing is already coded ... can u like try and walk us through by coding it not just explaining ... but I loved it though just need demonstration on the actually coding from scratch
reply

I have a question. In the remove function, if we use as a parameter a non-existing element in the list, it will throw an error don't?? We should check not to exceed the length of the list in order to avoid that I think.
reply

Thanks for making this video I really appreciate it! Just some feedback: You spoke really fast, I think it would've been better as a code along. All that code at the beginning can be pretty overwhelming
reply
Add a review, comment






Other channel videos