Thanks for the awesome explanation. I am also commenting the code for reversing the doubly linked list if it helps someone. public void reverse() { if (isEmpty()) return; Node temp = null; Node current = first; while (current != null) { temp = current.previous; current.previous= current.next; current.next = temp; current= current.previous; } if (temp != null) { first = temp.previous; } }
@rajanjha6732 жыл бұрын
Hello William Is it necessary to iterate in a clear method? What if we just set head and tail to null in java garbage collector should automatically reclaim that memory right?
@svrmmb Жыл бұрын
I believe it was primarily done with consideration for languages that lack garbage collection, such as C/C++.
@shankar74355 ай бұрын
It should be as per isolated islands logic of garbage collector clean up.
@VivekKumar-pp6cc2 жыл бұрын
Here after using remove (obj) Only remains head data acording to your implementation Like DL.add(12); DL.add(13); DL.add(14); DL.remove(13) It will return [12] according to your implementation But actual linked list return after removing remaining all data. DL.add(12); JDL.add(13); JDL.add(14); JDL.remove(13) It will return [12,14] according to java linked list. Why it different?
@aaryanrohra58312 жыл бұрын
Is that really java? That's really intimidating for beginners. Can you make tutorials for those as well?
@m1rac1e2 жыл бұрын
this is meant for someone that's taken 1 - 2 intro programming courses. Data structures/algorithms is usually the 2nd/3rd class that a CS major takes. after introducing these concepts: basic syntax, basic overview of object oriented programming, classes, templates, pointers & more. After you learn all that stuff, then this will make sense.
@k_chirsoo17295 ай бұрын
@@m1rac1e Btw what's is for?
@vovanhung94065 ай бұрын
@@k_chirsoo1729 it's call generics. u can search to learn more about it. but it's quite easy at all
@shankar74355 ай бұрын
@@k_chirsoo1729That scares many from Java and I love that as it works as a crowd limiting factor of Java programmers. Otherwise this world would have been filled with all Java developers and it's very difficult to survive with Java as core bread and butter stuff for the people like me with average IQ. Thanks to Generics and it's scary look.😂😂😂❤❤❤
@mbil4l4 ай бұрын
@@k_chirsoo1729 Used for declaring data type at runtime instead of hardcoding it. So, if I send LL will contain ints if then strings and so on.
@cr66964 жыл бұрын
Thank you
@this_is_mac3 жыл бұрын
You could've used one loop in remove()
@tiansuyu99658 ай бұрын
Yeh, I think the same. Doesn't matter the value is null or not, Null in most languages are singleton and comparison should work in that case.