Data Structures in Python: Doubly Linked Lists -- Append and Prepend

Поділитися
Вставка
  • Опубліковано 4 січ 2025

КОМЕНТАРІ • 143

  • @kimber8324
    @kimber8324 4 роки тому +10

    Happy to report that I completed the prepend function prior to un-pausing the video. This is a huge win for me and couldn't have done it without your singly linked lists and circular linked list videos. It's starting to click!

    • @LucidProgramming
      @LucidProgramming  4 роки тому +1

      Excellent! That's really great to hear. I'm loving hearing about your progress here, and I'm glad the content is starting to click. Cheers!

  • @Roshan-xd5tl
    @Roshan-xd5tl 3 роки тому +5

    Your playlists about single, double and circular linked lists are great. It really helped me. Thank you for your contribution. Cheers :)

  • @enkaibi2756
    @enkaibi2756 5 років тому +4

    Best video on Doubly lists after watching top videos in UA-cam. Well explained! Thanks!

    • @LucidProgramming
      @LucidProgramming  5 років тому

      Thank you! If you like my content, I've been working on some projects during the past couple of months. If you would like to stay up-to-date, please consider subscribing to my mail list. Also, if you haven't already, please consider subscribing! I really appreciate the support. I hope that the content I provide there will enhance the videos on my UA-cam page.
      bit.ly/lp_email

  • @Mithileshx
    @Mithileshx 4 роки тому +4

    I am trying to write programs before watching your videos and guess what?! I am totally able to! Thanks to your wonderful explanations of Singly Linked Lists, the picture has gotten perfectly clear in my head! God bless you man!

    • @LucidProgramming
      @LucidProgramming  4 роки тому +2

      Cheers! If you enjoyed and benefited from my content, please consider liking the video and subscribing to the channel for more content like this. If you would like to support the content creation on this channel please consider unblocking ads when watching my videos as this is how I support my time to make content. I hope to be putting out more similar videos soon!

  • @hackytech7494
    @hackytech7494 4 роки тому +1

    I have watched manny video's on linked list but never understood that concept completely. But after watching this video I understood the concept clearly and now my confidence is also booted and now I am not at all afraid of linked lists. Thank you so much

    • @LucidProgramming
      @LucidProgramming  4 роки тому +1

      Cheers! If you enjoyed and benefited from my content, please consider liking the video and subscribing to the channel for more content like this. If you would like to support the content creation on this channel please consider unblocking ads when watching my videos as this is how I support my time to make content. I hope to be putting out more similar videos soon!

    • @hackytech7494
      @hackytech7494 4 роки тому +1

      @@LucidProgramming yup..I did subscribed your channel when i saw your explanation..and yes on every video i gave a like.. your tutorial are so detailed to understand, even a noob can understand easily.... I was having manny doubts about linked list but after watching your tutorials all doubts were cleared. Thank you once again

    • @LucidProgramming
      @LucidProgramming  4 роки тому +1

      @@hackytech7494 That's great to hear, I'm really happy to hear that! Thank you again for the kind words!

  • @pythonenthusiast9292
    @pythonenthusiast9292 4 роки тому +1

    awesome , waiting for you to add more to this series.. it seriously deserves at least a million views, not even kidding

    • @LucidProgramming
      @LucidProgramming  4 роки тому +2

      Cheers! If you enjoyed and benefited from my content, please consider liking the video and subscribing to the channel for more content like this. If you would like to support the content creation on this channel please consider unblocking ads when watching my videos as this is how I support my time to make content. I hope to be putting out more similar videos soon!

    • @pythonenthusiast9292
      @pythonenthusiast9292 4 роки тому

      @@LucidProgrammingsure, waiting for them eagerly!!

    • @LucidProgramming
      @LucidProgramming  4 роки тому

      @@pythonenthusiast9292 Thanks! Really looking forward to getting to producing them. Cheers!

  • @emerold7
    @emerold7 6 років тому +5

    Really helpful! First time doing doubly linked lists and I was able to follow exactly what you did and why. Thank you!

    • @LucidProgramming
      @LucidProgramming  6 років тому

      Thank you, Megan! :) I'm really happy to hear that this video was helpful to you. Indeed, that always makes my day to hear! Best of luck in your learning of data structures and happy coding! :)

  • @OmegaOverlord3000
    @OmegaOverlord3000 6 років тому +4

    You do a very good job of explaining to someone who has never done programming before (like me) and I thank you for it. Keep up the good work!

    • @LucidProgramming
      @LucidProgramming  6 років тому

      Really appreciate that. I'm very happy to hear that you're gaining something from these videos. I do look forward to making more of these in the future, and best of luck on your programming journey! Cheers.

  • @prakashranjanpatra3539
    @prakashranjanpatra3539 5 років тому +3

    really helpful. the way you explained using diagram, helped me to code myself. Thank you very much.

  • @prabhanjantrivedi
    @prabhanjantrivedi 4 роки тому +3

    you are simply awesome. I was looking for some good video tutorial where i can revise DS using python and seems you are boon. I wonder how i stumble upon your lectures. you deserve more views !

    • @LucidProgramming
      @LucidProgramming  4 роки тому

      Thanks, and if you think that, please do share this content with others who you think might benefit from it as well! Cheers, and thanks for watching.

  • @prashanthnayak9859
    @prashanthnayak9859 5 років тому +3

    Honestly, i liked the way you used ppt as well as python editor. Great Explanation Sir. I,m Expecting many examples like circular, Dfs, Bfs, A*, Greedy, Tree Traversing, Graphs. Thank you once again.

    • @LucidProgramming
      @LucidProgramming  5 років тому

      Thank you! If you like my content, I've been working on some projects during the past couple of months. If you would like to stay up-to-date, please consider subscribing to my mail list. Also, if you haven't already, please consider subscribing!
      I really appreciate the support, and if you want to support the channel, I do have a PayPal link (www.paypal.me/VincentRusso1) for donations that go directly to the creation of content on this channel.
      I hope that the content I provide there will enhance the videos on my UA-cam page.
      bit.ly/lp_email

  • @nishantbanjade920
    @nishantbanjade920 4 роки тому +3

    Thank you sir, your code is simple and easy to understand and your explanation techniques is also very good. Subscribed the channel!

    • @LucidProgramming
      @LucidProgramming  4 роки тому +2

      Really appreciate that, and thank you for the support!

  • @mohammodroby8346
    @mohammodroby8346 6 місяців тому

    You have helped me a lot. Thank you for the tutorial

  • @MuhammedAli-yw2sd
    @MuhammedAli-yw2sd 6 років тому +6

    Explained perfectly, 90% of my problems with dLL ceased.

    • @LucidProgramming
      @LucidProgramming  6 років тому

      That's great to hear Muhammed. Thanks for your comment, and again, I'm thrilled to hear that! Cheers.

  • @mulhamjarjanazi1707
    @mulhamjarjanazi1707 5 років тому +20

    Thanks! perfect as usual.
    I have a little suggestion, I think that we don't need to assign new_node.next and new_node.prev to None in append() since they both are initialized to None in the Node class.

    • @LucidProgramming
      @LucidProgramming  5 років тому +4

      Thanks, and yes, I do appreciate the input! Thanks again! :)

    • @ahmedshehata9522
      @ahmedshehata9522 4 роки тому

      The Explanation is a good. Also you can new_node = Node(data) can be assigned only one time .

  • @thrilledjinx5151
    @thrilledjinx5151 2 роки тому +1

    OMG, really good video! really good! I just solve my algorithm assignment, thank you!!!!

    • @LucidProgramming
      @LucidProgramming  2 роки тому

      Cheers! If you enjoyed and benefited from my content, please consider liking the video and subscribing to the channel for more content like this. If you would like to support the content creation on this channel please consider unblocking ads when watching my videos as this is how I support my time to make content. I hope to be putting out more similar videos soon!

  • @LazerScalper
    @LazerScalper 6 років тому +1

    Thank you for the great video series, I'm really enjoying them as a refresher.
    I get that you can just use a variable and update its value on every iteration (like you did for example with append(self, data) or print_list(self) functions, but the problem is that you are creating a new object in memory with every iteration (imagine you have a file with millions of data in that doubly linked list file, so it's not memory efficient). and that's what you did in your class based solution too (you used "cur = self.head" and then you used while loop to update "cur" variable with every iteration (small file is fine, but a big file would require you a lot of extra unnecessary memory).
    My solution I came up with today is to use a recursive loop (which doesn't create any extra objects in memory), as it only takes input (update "node = node[1]" and returns value if condition is True).
    x = [1, [2, [3, None]]] # This is a simple doubly linked list
    def print_list(x):
    print(x[0])
    if x[1] is None:
    pass
    else:
    return print_list(x[1])
    print_list(x)
    # 1
    # 2
    # 3
    So basically, you just print the first element (data) and then you return by calling the function again but passing in the new value of "doubly[1]" list to be its 2nd element recursively.
    recursive solution is memory saver and efficient and just best practice in this situation in my opinion (memory saver, simple, and just clean).
    Your thoughts?

    • @LucidProgramming
      @LucidProgramming  6 років тому

      Hi Fouad. I'm not sure how you can construct a doubly linked list without treating the nodes as explicit objects and allocating memory for each of those nodes. Or perhaps I'm just misunderstanding the question that you're asking.

    • @LazerScalper
      @LazerScalper 6 років тому +1

      @@LucidProgramming oh no no, I think you got me wrong. When you first create the doubly linked list you definitely have to treat nodes as objects (as temporary variables).
      So, I'm not talking about when you first create the doubly list. I'm actually talking about the functions such as "append()", "prepend()", "print()", ...etc.
      I saw that all solutions on the internet (even on stackoverflow . com) they all use temporary variables with every iteration when traversing the nodes of the doubly list.
      But why use traditional iteration if you can use a better way? like using a recursive function (But keep in mind I'm applying Functional programming, not object oriented programming).
      For instance, in the case of the "print()" function, all you need is to pass to it the doubly list as an input, print the first node in it (read line 2 in my code above), then to go to the 2nd node, you don't have to use a temporary variable to go to 2nd node, instead, you can just call the same function "print()" within the function its self but this time pass the doubly list at position 1 (read line 11 in my code above).
      If you just copy and paste my code above as your "print()" function and test it, it will work fine. Test it as it is. Or use it in your code but pass "self" as input.
      The bottom line is that recursive functions don't need to use memory space with every iteration for them to work. thus you save memory as opposed to using variable and update it with every iteration requiring a new memory address with every iteration (as a new object is created with every iteration that the variable points to).

    • @kiwizor9962
      @kiwizor9962 2 роки тому

      @@LazerScalper i think when everyone does it one way and u do it the other, ur the wrong one? not attacking, just an honest comment

  • @sajanlawrence5964
    @sajanlawrence5964 4 роки тому +1

    Thank you sir......It is really very helpful ❣❣❣❣❣❣❣❣❣❣❣❣❣

    • @LucidProgramming
      @LucidProgramming  4 роки тому

      Cheers! If you enjoyed and benefited from my content, please consider liking the video and subscribing to the channel for more content like this. If you would like to support the content creation on this channel please consider unblocking ads when watching my videos as this is how I support my time to make content. I hope to be putting out more similar videos soon!

  • @ouroboros7388
    @ouroboros7388 2 роки тому +1

    Amazing video, thank you for the knowledge!!

    • @LucidProgramming
      @LucidProgramming  2 роки тому +1

      Cheers! If you enjoyed and benefited from my content, please consider liking the video and subscribing to the channel for more content like this. If you would like to support the content creation on this channel please consider unblocking ads when watching my videos as this is how I support my time to make content. I hope to be putting out more similar videos soon!

  • @mateuszsmendowski2677
    @mateuszsmendowski2677 5 років тому +1

    Could you make some series about code optimization? I love your videos. Very helpful during studies, a great source of knowledge!

    • @LucidProgramming
      @LucidProgramming  5 років тому

      Thanks! I like that idea. If you check out my Patreon page that I just launched, you can make these types of suggestions there. Thanks for watching! :)

  • @siddheshpujari25
    @siddheshpujari25 5 років тому +2

    Brilliant explanation, thanks a lot

    • @LucidProgramming
      @LucidProgramming  5 років тому

      Thank you! If you like my content, I've been working on some projects during the past couple of months. If you would like to stay up-to-date, please consider subscribing to my mail list. Also, if you haven't already, please consider subscribing!
      I really appreciate the support, and if you want to support the channel, I do have a PayPal link
      paypal.me/VincentRusso1
      for donations that go directly to the creation of content on this channel.
      I hope that the content I provide there will enhance the videos on my UA-cam page.
      bit.ly/lp_email

  • @DogeCharger
    @DogeCharger 4 роки тому +1

    By the way everyone, if you want to have a "smoother" implementation of displaying all the values, you can do something like this:
    by declaring this magic method in class Node:
    def __repr__(self):
    if self.next is None:
    return f'{self.data}'
    return f'{self.data} -> {self.next}'
    and then declaring this magic method in class DoublyLinkedList:
    def __repr__(self):
    return f'{self.head}'
    you can use print(dllist) to display all of the elements in a nice little format.

  • @Osraht
    @Osraht 5 років тому +1

    Your videos are very helpful. Thank you.

    • @LucidProgramming
      @LucidProgramming  5 років тому

      Thank you! If you like my content, I've been working on some projects during the past couple of months. If you would like to stay up-to-date, please consider subscribing to my mail list. Also, if you haven't already, please consider subscribing! I really appreciate the support. I hope that the content I provide there will enhance the videos on my UA-cam page.
      bit.ly/lp_email

  • @antoniastadler9396
    @antoniastadler9396 4 роки тому +1

    you save me.. thank you!! such a good tutorial!!

  • @amranmohamed377
    @amranmohamed377 3 роки тому

    Thanks a lot sir but since you initially assigned the next and prev values to none in __init__method is it must for u again to do the same in the prepend and append methods.

  • @cilpavincent3761
    @cilpavincent3761 2 роки тому

    Enjoying your videoes!
    Sharing my way of implementing insert_after() method:
    def insert_after(self,ref_data,data):
    new_node = Node(data)
    if not self.head:
    print('Empty list-reference node invalid!')
    return
    cur = self.head
    while cur:
    if cur.data == ref_data:
    new_node.previous = cur
    new_node.next = cur.next
    if cur.next: #last node has no cur.next
    cur.next.previous = new_node
    cur.next = new_node
    return
    cur = cur.next
    print('reference node not found in list')
    return

  • @VishnuGollakaram
    @VishnuGollakaram 3 роки тому

    @lucidprogramming wish you could complete the remaining ds series and get on with problem solving too
    Enjoying learning coding from your channel
    You're the best

    • @LucidProgramming
      @LucidProgramming  3 роки тому +1

      Been quite busy these days, but I sincerely appreciate your support!

  • @PranayZVlogs
    @PranayZVlogs 5 років тому +1

    Lovely explanation!

    • @LucidProgramming
      @LucidProgramming  5 років тому

      Thank you! If you like my content, I've been working on some projects during the past couple of months. If you would like to stay up-to-date, please consider subscribing to my mail list. Also, if you haven't already, please consider subscribing! I really appreciate the support. I hope that the content I provide there will enhance the videos on my UA-cam page.
      bit.ly/lp_email

    • @PranayZVlogs
      @PranayZVlogs 5 років тому +1

      @@LucidProgramming done!

    • @LucidProgramming
      @LucidProgramming  5 років тому

      @@PranayZVlogs Thank you! :)

  • @nulI_dev
    @nulI_dev 6 років тому +1

    Thanks, very clear explanations :)

    • @LucidProgramming
      @LucidProgramming  6 років тому

      Great to hear that, RB! If you like my content, I've been working on some projects during the past couple of months. If you would like to stay up-to-date, please consider subscribing to my mail list. Also, if you haven't already, please consider subscribing! I really appreciate the support. I hope that the content I provide there will enhance the videos on my UA-cam page.
      bit.ly/lp_email

  • @shazaibmaqsood2957
    @shazaibmaqsood2957 3 роки тому +1

    Great video

    • @LucidProgramming
      @LucidProgramming  3 роки тому

      Cheers! If you enjoyed and benefited from my content, please consider liking the video and subscribing to the channel for more content like this. If you would like to support the content creation on this channel please consider unblocking ads when watching my videos as this is how I support my time to make content. I hope to be putting out more similar videos soon!

  • @yashchauhan5710
    @yashchauhan5710 4 роки тому +1

    great and quality content

    • @LucidProgramming
      @LucidProgramming  4 роки тому

      Cheers! If you enjoyed and benefited from my content, please consider liking the video and subscribing to the channel for more content like this. If you would like to support the content creation on this channel please consider unblocking ads when watching my videos as this is how I support my time to make content. I hope to be putting out more similar videos soon!

  • @Sugurous
    @Sugurous 3 роки тому +1

    Man you're a plus

  • @debojitmandal8670
    @debojitmandal8670 Місяць тому

    Then what about link bw them in reverse bcs previous head also will have current.next memory location just like reversed linked list and u dint use while loop to do it

  • @fabiotrucco7969
    @fabiotrucco7969 3 роки тому

    Keeping track of a tail pointer would improve the efficiency of the append and other methods to O(1), which is the main reason why we are riddling our selfs with all this code instead of using a plain list, right?
    Thank you very much for your work!

    • @LucidProgramming
      @LucidProgramming  3 роки тому

      We are mostly going through this to understand the notion of a linked list. Cheers!

  • @talhaamir9023
    @talhaamir9023 5 років тому +1

    great work keep it up appreciated.

    • @LucidProgramming
      @LucidProgramming  5 років тому

      Thank you! If you like my content, I've been working on some projects during the past couple of months. If you would like to stay up-to-date, please consider subscribing to my mail list. Also, if you haven't already, please consider subscribing!
      I really appreciate the support, and if you want to support the channel, I do have a PayPal link
      paypal.me/VincentRusso1
      for donations that go directly to the creation of content on this channel.
      I hope that the content I provide there will enhance the videos on my UA-cam page.
      bit.ly/lp_email

  • @msugal
    @msugal 5 років тому

    Hi Vincent, do you think you will add Graph Algorithms. I searched everywhere for tutorial as good as yours but couldn't find. Graph algorithms are really important and I wish if you could add those videos in your Data Structures playlist.

  • @jojoesekyisagoe
    @jojoesekyisagoe 5 років тому

    I am little confused about something. The Node() class already had self.prev set to None in the init function. Why do you have to set self.prev to None again in the linked list append function in the loop (if self.head is None)? is the same task not already completed in the line
    new_node = Node(data) ????????????????

    • @LucidProgramming
      @LucidProgramming  5 років тому

      Sure, in this case, that might be redundant. You could get rid of that line in this case if you wanted to.

  • @ahmedalmohammed9022
    @ahmedalmohammed9022 4 роки тому +1

    Thanks you are great ^-^

    • @LucidProgramming
      @LucidProgramming  4 роки тому

      Cheers! If you enjoyed and benefited from my content, please consider liking the video and subscribing to the channel for more content like this. If you would like to support the content creation on this channel please consider unblocking ads when watching my videos as this is how I support my time to make content. I hope to be putting out more similar videos soon!

  • @sarasalam1766
    @sarasalam1766 5 років тому +1

    Thank you for the videos. They are really helpful.
    I have a question about the prepend method. For the first case, is it ok if we do not say "new_node.prev = None" like bellow: (I mean in the Node class we have already told that node.prev is none.)
    def prepend(self, data):
    if self.head is None:
    new_node = Node(data)
    self.head = new_node

    • @LucidProgramming
      @LucidProgramming  5 років тому +1

      Hi Sara. Thanks for that comment, I'm glad the videos have proved useful to you. Regarding your question, you may not need that line as it's done in the constructor beforehand. At worst, that line would be redundant from looking at this again. Unless I'm missing some edge case, I believe you can remove it. Thanks for the question!

    • @sarasalam1766
      @sarasalam1766 5 років тому +1

      @@LucidProgramming Thanks for the reply.

    • @LucidProgramming
      @LucidProgramming  5 років тому +1

      @@sarasalam1766 No problem, hope it helped!

  • @prabaldutta6744
    @prabaldutta6744 5 років тому

    Hi @LucidProgramming. The time complexity of the append function is O(n) and that of prepend is O(1) according to your code. Can you suggest improving the append function from O(n) to O(1) using a tail pointer?

    • @LucidProgramming
      @LucidProgramming  5 років тому

      You definitely could do that if you wanted to. It's up to you if you want to take on the additional overhead of keeping track of the tail pointer.

  • @sharkPause1
    @sharkPause1 3 роки тому

    Thank you dude

  • @FarisSkt
    @FarisSkt 4 роки тому +1

    nice stuff

  • @LazerScalper
    @LazerScalper 6 років тому +1

    Hi @LucidProgramming
    Thank you very much for the time and effort you're putting here. I only have one question: I'm implementing the same as your custom functions here (for a project), but not using classes. I know how to traverse a double linked list using classes (I knowt the "self. next" should do it), but I couldn't find anyway to traverse the doubly linked list without without using classes.
    I want to traverse it without modifying it (just like when using classes we only need to use self. next of the defined Node class).
    In other words: I want to traverse it and then do whatever I want BUT in place (append or add or delete or reverse, ...etc but in place), without creating another list, without using classes.
    Any idea?

    • @LucidProgramming
      @LucidProgramming  6 років тому

      Hi Fouad. No problem, I'm glad you found the video to be useful.
      Regarding your question. I think I understand. You essentially want to implement this without using classes? Sure, that's possible. Classes are just a nice way to organize concepts that happen to have similar traits or properties. There's nothing specific about the use of classes that makes solving this problem proprietary. You should just be able to replace any of the usages of the class with some variables and that should do the trick. Hope that makes sense. Cheers.

    • @LazerScalper
      @LazerScalper 6 років тому

      @@LucidProgramming yup I understand, and I really appreciate it, but you are using a variable that creates a new object in memory with every iteration (think in case you have millions of data). not memory efficient solution. but works with small files/data

    • @LucidProgramming
      @LucidProgramming  6 років тому

      @@LazerScalper Hi Fouad. What variable would you be referring to? I'm not exactly sure what part of the code you're mentioning here.

    • @LazerScalper
      @LazerScalper 6 років тому

      @@LucidProgramming I think the reason why you couldn't get my point is because I used functional and procedural programming in my code while you used object oriented programming.

    • @LucidProgramming
      @LucidProgramming  6 років тому

      @@LazerScalper Hi Fouad. Hmm, I'm not sure if that's the reason. I could be missing something, but I'm not sure that the reason for that is because the paradigm you are using is functional while the paradigm I'm using is object oriented. The issue seems to be a question as to whether or not an object is instantiated in memory or not, but I don't think the paradigm is the problem for our misunderstanding. Unless, perhaps I'm missing something.

  • @foralx
    @foralx Рік тому

    thank you !

  • @franklin6672
    @franklin6672 5 років тому

    hey, I just have a question about the if statement of append function, in what situation the self.head would be None? Thanks

    • @LucidProgramming
      @LucidProgramming  5 років тому +1

      We set it to None, so if nothing is put into the head, it would be None, for instance.

  • @venkateshprasad6432
    @venkateshprasad6432 6 років тому +1

    hey lucid thanks a lot for the tutorial man, i have a small doubt- in the prepend block instead of new_node.prev=none, shouldn't be self .head.prev=none? coz we assigned new node to self.head right?

    • @LucidProgramming
      @LucidProgramming  6 років тому

      Hi Venkatesh. Thanks for the comment. Have you tried making this change? If so, have you noticed any behavior that is unexpected? My suggestion would be to figure out why that won't work, and then go from there. Hope that helps, and thanks for your comment!

    • @rajeshkab
      @rajeshkab 5 років тому +1

      First of all there is no need to set new_node.prev or new_node.next to None in any of these append and prepend methods, coz we have already initialised them in Node class __init__.

  • @Mrpoised
    @Mrpoised 5 років тому +1

    Thank You

    • @LucidProgramming
      @LucidProgramming  5 років тому

      No problem, thanks for watching and for the comment! :)

  • @marthalanaveen
    @marthalanaveen 6 років тому +2

    you made it cakewalk for me. Thanks and really helpful. BTW, github link is not working now. Do consider updating them.

    • @LucidProgramming
      @LucidProgramming  6 років тому +2

      Hi Naveen. I'm thrilled to hear that this video was helpful for you. I also appreciate you mentioning that the link in the description is broken. Indeed, I've gone ahead and updated the link. Thank you very much for pointing that out! Cheers, and thanks again for watching.

  • @anonym58063
    @anonym58063 6 років тому +1

    Can you make a video about sorting datas in doubly linked list?

    • @LucidProgramming
      @LucidProgramming  6 років тому

      That's definitely on my "to-do" list. Thanks for your suggestion!

  • @projectaddictive5226
    @projectaddictive5226 5 років тому

    hello bro, I have seen many of your video tutorials, may I ask for the presentation to be used as my study material for this video.? thx u :)

  • @yashpandey350
    @yashpandey350 4 роки тому +1

    I caught the error of not updating (cur.next = new_node) before you. Yipeeeeeeeee

  • @discoverthecode2286
    @discoverthecode2286 2 роки тому

    thanks mem

  • @cilpavincent3761
    @cilpavincent3761 2 роки тому

    insert_before() method:
    def insert_before(self,ref_data,data):
    new_node = Node(data)
    if not self.head:
    print('Empty list-reference node invalid!')
    return
    cur = self.head
    while cur:
    if cur.data == ref_data:
    if cur.previous is None:
    self.head = new_node
    else:
    cur.previous.next = new_node
    cur.previous = new_node
    new_node.next = cur
    return
    cur = cur.next
    print('reference node not found in list')
    return

  • @gunahawk6893
    @gunahawk6893 2 роки тому +1

    i tried like this def append(self,data):
    newNode = Node(data)
    temp = self.tail
    self.tail = newNode
    self.tail.prev = temp.data
    self.head.next = newNode.data
    self.length += 1

    • @LucidProgramming
      @LucidProgramming  2 роки тому +1

      Nice, thank you for sharing!

    • @gunahawk6893
      @gunahawk6893 2 роки тому

      @@LucidProgramming thanks man , your dsa course content is very good any idea for making new playlist for interviews like design round or leetcode problems ?

    • @LucidProgramming
      @LucidProgramming  2 роки тому +1

      @@gunahawk6893 Thank you very much! Honestly, if I am able to find the time, I would love to do something like that!

    • @gunahawk6893
      @gunahawk6893 2 роки тому

      @@LucidProgramming thanks man have a nice day

  • @yashchauhan5710
    @yashchauhan5710 4 роки тому

    why didnt you used tail pointer ..wiull be give us 0(1) time in append and prepend

    • @LucidProgramming
      @LucidProgramming  4 роки тому

      Not sure I understand the comment.

    • @yashchauhan5710
      @yashchauhan5710 4 роки тому

      @@LucidProgramming I mean you could use a tail pointer to point to the end node and deletion from end or insertion will be 0(1)

    • @LucidProgramming
      @LucidProgramming  4 роки тому +1

      @@yashchauhan5710 Oh, sure, you could do that.

  • @njoy2075
    @njoy2075 4 роки тому

    This prepend is basically assigning a new head .

    • @LucidProgramming
      @LucidProgramming  4 роки тому +1

      Yes, exactly.

    • @njoy2075
      @njoy2075 4 роки тому

      @@LucidProgramming This set of videos are really nice. Thank you for the content.

    • @LucidProgramming
      @LucidProgramming  4 роки тому

      @@njoy2075 Cheers! If you enjoyed and benefited from my content, please consider liking the video and subscribing to the channel for more content like this. I hope to be putting out more similar videos soon!

  • @springbootguy
    @springbootguy 3 роки тому

    you did a lot of not needed code example in prepend u don't need that if statement
    u could put the else block code direclty it will work

    • @LucidProgramming
      @LucidProgramming  3 роки тому

      Some parts of it could probably be extracted, but you'll want to catch the two different conditions of when you're prepending to an empty list of a non-empty list.