Data Structures and Algorithms in Ruby: Linked Lists #2

  Рет қаралды 2,056

Conner Jensen

Conner Jensen

2 жыл бұрын

In this linked list video we implement the prepend and remove methods which allow us to add a node to the beginning of our linked list and remove a node from our linked list.
If you haven't watched it yet here is a link to part 1 of this video series: • Data Structures and Al...

Пікірлер: 22
@santaclause1988ify
@santaclause1988ify 2 жыл бұрын
More data structure and algorithm videos please
@connerjensen8170
@connerjensen8170 2 жыл бұрын
More videos on ROR and Ruby to come! Please let me know if you have any video suggestions. Thanks for watching!
@yasinowen
@yasinowen 2 жыл бұрын
Create a top level crud api and tricks
@yasinowen
@yasinowen 2 жыл бұрын
next video RoR tricks.
@jetspray3
@jetspray3 2 жыл бұрын
And just a few months ago I learn there is an implicit self created if you used an instance method in another method. It makes me reflect on the implicit return created at the end of a method.
@VictorBStan
@VictorBStan 2 жыл бұрын
Also, if you're working with adding and removing values, you could potentially add the same value multiple times, then remove one of them, but still find that you have a node with the same value. maybe that's a feature, maybe that's a bug, depends on how you might use your linked list. another options is to use 'indexes'. so you can insert values in between nodes as well. just some thoughts. There are many ways to implement linked lists :)
@connerjensen8170
@connerjensen8170 2 жыл бұрын
Awesome suggestions and thoughts Victor! I appreciate your feedback.
@GokuSan389
@GokuSan389 2 жыл бұрын
Hello, nice videos. Just a small tip :) I believe you could, instead of always calling Node.new(value, nil), assign nextNode = nil in initialize method as default value. Also a question why do you have class in class ??
@connerjensen8170
@connerjensen8170 2 жыл бұрын
Yes, you are right. Thanks!
@chantalwobben7518
@chantalwobben7518 2 жыл бұрын
Maybe a idea for video 3 how to reverse a linkedList ?
@RR-et6zp
@RR-et6zp Жыл бұрын
Can you explain what a node is? and what an edge is ? is it like the title of the data structure ? how stuff interacts with each other
@sidduh5607
@sidduh5607 2 жыл бұрын
I think in remove method, we need to make self.head = node.nextNode if we are trying to remove first node.
@ritikagakher9688
@ritikagakher9688 6 ай бұрын
More DS videos please 🙏
@connerjensen8170
@connerjensen8170 5 ай бұрын
Long time off, but working on more content now!
@ulyssebuonomo4148
@ulyssebuonomo4148 2 жыл бұрын
Prepend could really be a one liner, no need for nil check. self.head = Node.new value, head
@jazthomson1171
@jazthomson1171 2 жыл бұрын
Sorry but I think there might be a bug in your remove method - if you remove the head when there are more nodes after it, how will you manage to traverse to those nodes? Perhaps I am misunderstanding. Nice video regardless :)
@GokuSan389
@GokuSan389 2 жыл бұрын
I second that. He has a bug in the remove method. I have implemented a print_list method and it stops due to the return if head.nil? It should be return self.head = node.next_node if node.value.eql?( value ) So first you set node = head than prev_node = nil and than the return and than the until loop....
@connerjensen8170
@connerjensen8170 2 жыл бұрын
Yes, you are right. Sorry about this error
@VictorBStan
@VictorBStan 2 жыл бұрын
Also curious, maybe someone already mentioned, but it's common to use @val (instance variables), self.val usually used for class variables. attr_* gives you the methods to get/set instance variables on an object, so in initialize just use @val and @next_node; then you can just say object.val/object.next_node and object.val = 'val', object.next_node = 'val'.
@MoeNegm
@MoeNegm 2 жыл бұрын
so i tried this and i think there is a bug in your remove method. here is my test: ll = LinkedList.new ll.add(10) ll.add(20) ll.prepend(5) puts ll.head.value #5 puts ll.head.nextNode.value #10 puts ll.head.nextNode.nextNode.value #20 puts ll.find(10) #true puts ll.find(50) #false puts ll.find(20) #true puts ll.find(50) #false puts ll.find(10) #true ll.remove(5) puts ll.head.value #undefined method `value' for nil:NilClass puts ll.head.nextNode.value this is not working for when you remove the first node in the list, it does work if i remove the second or third. but not the first
@MoeNegm
@MoeNegm 2 жыл бұрын
here is how i solved it: def remove(value) return if head.nil? node = self.head prev_node = nil return self.head = self.head.nextNode if node.value == value while node && value != self.head if node.value == value if prev_node prev_node.nextNode = node.nextNode return else self.head = nil return end end prev_node = node node = node.nextNode end end
@MoeNegm
@MoeNegm 2 жыл бұрын
thanks to your two videos, i feel comfortable enough with nodes now where as they were a complete mystery before. Keep up the great work, I'll be subscribing.
Data Structures and Algorithms in Ruby: Binary Trees
14:26
Conner Jensen
Рет қаралды 3 М.
Data Structures and Algorithms in Ruby: Linked Lists
14:51
Conner Jensen
Рет қаралды 6 М.
Let's all try it too‼︎#magic#tenge
00:26
Nonomen ノノメン
Рет қаралды 54 МЛН
Do you have a friend like this? 🤣#shorts
00:12
dednahype
Рет қаралды 11 МЛН
Buy Feastables, Win Unlimited Money
00:51
MrBeast 2
Рет қаралды 98 МЛН
I PEELED OFF THE CARDBOARD WATERMELON!#asmr
00:56
HAYATAKU はやたく
Рет қаралды 35 МЛН
10 Key Data Structures We Use Every Day
8:43
ByteByteGo
Рет қаралды 318 М.
RSpec Tutorial #1: Getting Started With RSpec
9:00
Conner Jensen
Рет қаралды 20 М.
2. Data Structures and Dynamic Arrays
50:18
MIT OpenCourseWare
Рет қаралды 481 М.
Google Data Center 360° Tour
8:29
Google Cloud Tech
Рет қаралды 5 МЛН
Top 6 Coding Interview Concepts (Data Structures & Algorithms)
10:51
Bjarne Stroustrup: C++ | Lex Fridman Podcast #48
1:47:13
Lex Fridman
Рет қаралды 1 МЛН
Binary Tree Algorithms for Technical Interviews - Full Course
1:48:53
freeCodeCamp.org
Рет қаралды 683 М.
My Initial Impresson Of Go
12:39
TheVimeagen
Рет қаралды 39 М.
Data Structures & Algorithms #1 - What Are Data Structures?
16:35
Let's all try it too‼︎#magic#tenge
00:26
Nonomen ノノメン
Рет қаралды 54 МЛН