Data Structures in Python: Singly Linked Lists -- Deletion

Поділитися
Вставка
  • Опубліковано 22 жов 2024

КОМЕНТАРІ • 165

  • @haozhang9519
    @haozhang9519 5 років тому +33

    A very good tutorial, helps a lot, thank you. There is a small mistake while Zhu Qiaochu has mentioned previously.
    The init count value should be set to 0 because the while loop starts from the head node not head.next.
    Try to insert at pos 1, count == pos, this will break the loop without entering it.
    In this case, prev is still None, so a null pointer error will raise.

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

      Thank you for the comment, Hao! And thank you for clarifying the mistake. Always trying to improve my content and make it better, so I appreciate the feedback! Cheers!

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

      yea setting count = 0 is much better than,
      prev = self.head
      cur_node = self.head.next
      count = 1
      which I did.. :P

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

      Thanks, man, I couldn't be able to understand why this is not working.

  • @rakshitpuri4192
    @rakshitpuri4192 4 роки тому +7

    The previous video's explanation was so good that I came up with the delete function on my own. Great channel!

    • @LucidProgramming
      @LucidProgramming  4 роки тому +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!

  • @antrikshgupta418
    @antrikshgupta418 4 роки тому +5

    Actually I was so much stressed to work with data structures specially with python , then I found your videos which took me ashore and thanks a lot for all this amazing stuff.....Keep doing the great work . Hope to continue the tech journey along with you.. :D

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

      Happy to hear that, thanks for the kind words and best of luck to you in your journey!

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

    seriously, you're the best. I was a little bit too brave and enrolled in a programming class that is waay above my league. I need to work with binary search trees for homework now. But before I am able to do THAT, I want to get behind the logic of linked lists first. You make this possible! Thank you so much

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

      Hi Pieni. Thank you very much. Hearing things like this really makes the time and effort I put into these videos very worthwhile.
      Indeed, I've turned to UA-cam for many things that I felt the same way about and have benefited immensely from others who have also taken the time to teach.
      I wish you all the best in your class. If you feel like you've benefited from the content, feel free to subscribe and check out some of the other content I have on binary trees and binary search trees in Python. Cheers!

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

    I have been looking for linked list tutorials in python and also read some blogs on it but your videos helped me the most.

    • @LucidProgramming
      @LucidProgramming  3 роки тому +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!

  • @pabloalfaro2595
    @pabloalfaro2595 3 роки тому +2

    You are a GOD! Really helped me out in my Data Structures class since i'm doing it in Python instead of java

    • @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!

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

    In function delete_node_at_pos(), count should start from 0, instead of 1,
    if you give count = 1and if you want to delete at position 1, then program will not go inside the while loop as count != pos.
    Thanks.

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

      Doesn't the first "if" statement above this account for that scenario?

    • @lol-ki5pd
      @lol-ki5pd 4 роки тому +1

      @@LucidProgramming actually we have to start count from 0 ...I tried and count =1 is not working...I am getting the error of "NONETYPE OBJECT has no attribute 'next'

    • @lol-ki5pd
      @lol-ki5pd 4 роки тому

      The problem is that... If I wanna delete something at 1 then ...it won't enter into while and previous.next (previous is none) is wrong...as none doesn't have 'next' attribute

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

      In function delete_node_at_pos(), the problem is not with count Instead change prev =None to prev = self.head
      thanks!!

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

      @@thilakreddy13 Thank you so much! I had a hard time figuring out the problem with this NoneType error

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

    This video deserves way lot of views than it is!

    • @LucidProgramming
      @LucidProgramming  3 роки тому +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!

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

      @@LucidProgramming done brother 😊

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

      @@geekyprogrammer4831 Very much appreciated! Thank you!

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

    Nice tutorial! I liked it and learned easily. However, knowing which video I should follow after a video or which is the first is relatively difficult. I wish you numbered videos about each topic like Linked List 1 (Insertion), Linked List 2 (Deletion), etc. If there is a way to easily understand it please let me know by answering this comment. Thanks for great tutorial.

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

    bro, even until now your video is still help a lot of people, really appreciate your content bro so i make sure, i didn't skip any of ads in your video. 👌👌🐱‍🚀

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

      Very much appreciated. From one Vincent to another, thank you!

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

    Superb explaination ......
    TQ so much...

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

      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

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

    thank you for the great tutorial!! helped me a lot with my understanding and coding of the linked list. flunked my test because linked list had a great weightage on the exam and after watching this, i could code it well without even referring to the codes over and over. thank you so much

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

      Really glad to hear the video helped. Sometimes some extra practice and some visuals help to solidify things. Thanks for the comment and for watching!

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

    very clean explanations, brilliant

    • @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!

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

    Excellent tutorial
    Thanks! I've been searching for data structures written in python but all I found are written in other languages or explained as algorithms
    Slight correction at 14:32 the count should be set to zero. As I am new to ds, it took me some time and a lot of frustration to correct it myself checking and rechecking the code again and again 😅
    Please correct it in the comments and pin it so that others don't go through the same pain

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

      Nice! I believe this is updated on my GitHub code. Thanks for pointing this out in any case!

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

    Your videos are really helpful. Amazing work!

  • @bayan7417
    @bayan7417 3 роки тому +3

    Dude you are an absolute life saver, your explanations are very clear and concise, and they actually make sense. Keep it up!

    • @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!

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

      @@LucidProgramming yes agreed to bayan
      we want more DS

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

      @@mightyprogrammer2899 Thank you both for the encouragement! I hope that I can find the time to put out some new videos!

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

    TY! great tutorials on linked lists. Using these as study guide for my technical interview

    • @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!

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

    i too observed count should start from 0. by the way very good series . i am planning to do all the videos in coming days

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

      Good luck on your journey with the videos! I hope you enjoy the process! :)

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

      As @LucidProgramming mentioned that before that only he kept the 0 value to Cur or to head value, So he started of with count = 1, in the case were pos is not equal to head.

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

    You have the best videos

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

      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

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

    14:33 I think count should start at 0 if the first node is gonna be the head. Otherwise you get an off by one error (imagine a list with a single node, and you're asked to remove element number 1). I'm assuming the head is at position 0.

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

      The videos are great btw, I hope I didn't come off cocky, I was just trying to help (and clarify my doubts)

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

      @@lukpisimoh Not at all, in fact, the quality of these videos is directly tied to my great audience and their feedback. The code on my GitHub does have this updated change. Thank you for posting the comment, and thank you for taking the time to mention that here. I appreciate your viewership and support!

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

    Just marvellous

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

      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

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

    Great explanation

    • @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!

  • @WannaBe-21
    @WannaBe-21 5 років тому +9

    Thanks bro it helped me a lot Genuinely nice content. Instead of reading 100 of blogs in internet. Just check it out :D

    • @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

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

    I have a query!! While deleting a node, shouldn't we delete the object itself instead of setting it to None in order to free the memory space?
    By the way, I really appreciate the effort you put into these videos. Have helped me a lot in my learning process.

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

      It depends on the requirements. One could consider deleting the object or setting to None depending on what is asked and what the use case is.

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

      Thank you for answering.

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

      @@b_sobhan_ Of course, thank you for watching.

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

    Great 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, 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

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

    Excellent! sir, please give us the series of "Data structures using Recursion"

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

      Thank you! I do indeed have a Recursion playlist here: bit.ly/lp_recursion

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

    what if the node we want to remove is the last one,? because lastnode.next will also going to be none please explain

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

    Great Tutorial , thanks a lot .

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

      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

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

    what about if list is empty and you try to delete at pos. i don't see a check that head is not none. does that matter?

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

    del_at_position is not working for '1' position.But,its working fine for others.Plz clarify.

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

      It's working fine for me. Could you provide a complete example?

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

      Tried to execute your github code with delete_node_at_pos(1). Its throwing a attribute error: ‘NoneType’ object has no attribute ‘next’.

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

      @@rohithreddysureddy9151 Ah gotcha. I believe changing "count = 1" to "count = 0" solves the problem. I updated the code on my Github as well to reflect this. Thanks for pointing that out!

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

      Thanks a lot vinnie.. Superb teaching style and great videos..keep going ..
      Wish u would do more videos especially on time efficiency and space efficiency and complete data structures..

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

      @@rohithreddysureddy9151 Thank you, Rohith! I hope to continue making more videos on this channel. Thank you for your encouragement and support!

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

    Thank you very much.

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

    Was very helpful. Thankyou :)

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

      And yes...count should start from 0 because if its started with 1, for pos = 1, the prev = None and therefore has no attribute "next"

    • @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

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

    Thanks. This helps me learn. May I know how to delete from the tail? I always get Nonetype object has no attribute next.

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

      No problem, I hope the video was helpful. If you know the length, then you could just delete it at that position using the function we wrote.

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

    Sir, i have one question
    Delete the last node from linked list without head pointer.
    how can we do this?
    i mean is this even possible to do?

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

      Have you tried anything to solve this problem?

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

      @@LucidProgramming yes i tried this method
      def deleteNode(node_ptr):
      temp = node_ptr.next
      node_ptr.data = temp.data
      node_ptr.next = temp.next
      but using this method we cant delete last node.
      btw thanks for replying:)

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

      @@shreyaskadoor3582 Couldn't you add an if statement to check for the last node condition?

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

    At 13:00 don't we also need to check if the linked list isn't empty altogether? If it is empty then I think an error will be raised saying None(object) which is self.head has no attribute next

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

      btw great video

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

      Wouldn't it be a bit more helpful to the user to explicitly cover this case though?

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

      @@KshitijKale And thank you! :)

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

      I agree that we need a different condition to remove the first element different from the logic for middle elements. But what i actually meant was:
      In the line, self.head = current_node.next it would give a error if the linked list was empty as current_node is self.head and in a empty list self.head is not assigned to any "node object" and thus does not have a next attribute.
      So in the if condition, rather than,
      If pos==0: #now
      I think it should be
      If pos==0 and self.head != None:
      I am sorry for making it so long, hope I cleared my question.

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

      @@KshitijKale Oh okay, gotcha. Yeah, I think that makes sense to me!

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

    Great content. However, a test of llist.delete_node_at_pos(1) will fail the code. Because the current code doesn't cover the case of count==pos right off the bat. A minor change to the while loop would fix it:
    while True:
    prev = cur_node
    cur_node = cur_node.next
    if cur_node is None or count == pos:
    break
    count += 1

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

      Cool, feel free to make a pull request to improve the GitHub code in the description! Cheers!

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

    Great tutorial! Would you mine explaining a bit more what “self” means! I get the code, but I want to understand what self is.

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

      "self" is a keyword that refers to the instance of the class. I would suggest Googling around for "classes in Python" for further info.

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

      LucidProgramming ahh ok gotcha! Will do!

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

      @@rumikinss9125 I offer one-on-one consulting for Python, so if you want to book a session, I'd be happy to go into more detail for you!

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

      LucidProgramming thanks for the offer, but im a broke college student!

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

      @@rumikinss9125 No worries, I appreciate the support and viewership :)

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

    What does setting cur_node to None accomplish? Does it deallocate memory taken up by the deleted node?

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

      Hey Yongguang. Setting the variable to None is precisely the same idea as setting the variable to "null" when implementing a linked list in language like C++ or Java. When implementing these things in C++/Java, you want to make sure that you do indeed set the nodes to null when they stop pointing to other nodes in the list so as to avoid "dangling pointers". It's kind of the same idea here, although most likely nothing catastrophic will happen if you don't, it's just good practice. Hope that makes sense, and thanks for watching!

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

      Make sense. Thank you so much for reply!

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

      Is the cur node a local variable that will be automatically collected after the method return? Is it only a ritual code here to set it to None? Please help clarify.

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

    Can someone explain the part on
    def delete(self, key):
    cur_node = self.head
    if cur_node and cur_node.data == key (what does this mean? the current node data is equal to the key we seek?)
    self.head = cur.node.next
    cur_node = None

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

      If the current node exists and the data held at that node is equal to the key.

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

    can I get the link to the ppt which you used? btw great video thanks

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

      Updated the description with a link to the slides. Cheers, and thanks for watching!

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

      @@LucidProgramming thanks

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

      @@LucidProgramming great series bro please upload more like backtracking bfs dfs or many sorting algos

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

      @@subhambanerjee6334 It's on my to-do list! Thanks for watching! :)

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

    Thank you very much. But it won't delete if the linked list has duplicates though. :)

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

      You're welcome, and you're right. Not sure if I mentioned that I assumed the list entries were unique. Sorry about that!

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

      @@LucidProgramming You did mention that. I was excited to try it on my own. I didn't look at that. Sorry about that! Thank you!

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

      @@vayunandu No worries, thanks for the comment all the same!

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

      @@vayunandu I tried solving it for duplicates and this is what I came up with: 🙂
      def remove(self, key):
      remove_count = 0
      while self.head.data == key and self.head:
      remove_count += 1
      self.head = self.head.next
      if not self.head:
      return f'node {key} was removed {remove_count} times
      list is empty'
      prev_node = self.head
      cur_node = prev_node.next
      while cur_node:
      if cur_node.data == key:
      prev_node.next = cur_node.next
      cur_node = None
      remove_count += 1
      else:
      prev_node = cur_node
      cur_node = prev_node.next
      return f'node {key} was removed {remove_count} times'

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

    Initial assigning of count will be Zero not One
    Count=0 ✓
    Count=1×
    Then only it iterates the loop.

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

      Have you run the code on my GitHub? Setting `count=1` works as expected.

  • @lol-ki5pd
    @lol-ki5pd 4 роки тому

    LucidProgramming actually we have to start count from 0 ...I tried and count =1 is not working...I am getting the error of "NONETYPE OBJECT has no attribute 'next'

    • @lol-ki5pd
      @lol-ki5pd 4 роки тому

      The problem is that... If I wanna delete something at 1 then ...it won't enter into while and previous.next (previous is none) is none...and none doesn't have 'next' attribute

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

      Are you referring to a specific spot in the video? Are you sure your code is consistent with my code on GitHub?

    • @lol-ki5pd
      @lol-ki5pd 4 роки тому

      @@LucidProgramming at 14:31 you initialized count by 1 but it should be 0

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

      @@lol-ki5pd Ah, that's correct. I must have altered that on my GitHub because the code there is correct. Thanks for catching that.

    • @lol-ki5pd
      @lol-ki5pd 4 роки тому +1

      @@LucidProgramming no problem :) btw you are the best teacher I ever had

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

    deleting at given position is not working correctly plx help

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

      How? You haven't given me any more information so I can't help you.

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

      @@LucidProgramming when you try to delete "C" or "D" , it is still deleting only "B" for some reason. I have the same issue and i am not understanding the reason behind it

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

      @@akhilvarma1 Are you sure you're running the right code? I just ran the code on my GitHub and it works as expected.

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

    Amazing😍😍😍😍😍😍😍😍😍😍😍😍😍😍😍😍😍😍😍😍😍

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

      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

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

    Initial value of count must be 0

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

      Hi Zhu. Since we explicitly check for pos = 0 prior to running our loop, we already explicitly take care of this case. Since the remainder of the code goes from node 1 on, starting the count at 1 appears to be okay, unless I'm missing something.

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

      yes, try run the code, you will see. Your work is pretty awesome. I like the videos!!

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

      Hmm, I will indeed follow-up on that. Also, thank you very much for your kind comment, I'm happy to hear that you like the content :)

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

      Hi. Zhu Qiaochu is right. Count should be initialized to 0 because the cur_node starts from the head node(0th position).

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

      if pos == 1 the while loop will not be entered. thus the head is cur node which will be deleted. error

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

    finally after hours 1 like

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

      Thanks, Kelvin. I appreciate the like! Cheers, and thanks for watching.

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

    when deleting a node that is not the head, can't you just point the prev node to the next.next? why do you care about setting the deleted node next to None?

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

      That's more of an artifact of languages like "C" that would prevent things like "dangling pointers".

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

    The one dislike is from a person who died million years back... :P:P

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

    delete node at position is not working because when the position is 1, both while loop and if conditional don't run and prevNode is still None, and prevNode.next (next of None is not valid).
    the following code works
    def delNodePosition(self, position):
    currentNode = self.head
    if(position == 0):
    self.head = currentNode.next
    currentNode = None
    return
    count = 1
    prevNode = currentNode
    currentNode = currentNode.next
    while(currentNode and count != position):
    prevNode = currentNode
    currentNode = currentNode.next
    count += 1
    if currentNode is None:
    return
    prevNode.next = currentNode.next

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

    count from 1 wont work it should be 0

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

    Someone helppp:
    def del_pos(self, data):
    curr_node=self.head
    for i in range(0,data):
    curr_node=curr_node.next
    prev_node=None
    for i in range(0,data-1):
    prev_node=prev_node.next
    prev_node.next=curr_node.next
    curr_node.next=None

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

      I would encourage you to pepper in some print statements to see why your code might not be working as expected.

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

    This is good content, but man do you speak too fast for me to grasp everything!

    • @LucidProgramming
      @LucidProgramming  Рік тому +1

      The beauty of UA-cam is that you can replay and control the speed. Thanks for watching, and glad to hear it was broadly useful to you!

    • @nisargbhatt4967
      @nisargbhatt4967 Рік тому +1

      @@LucidProgramming Getting accustomised gradually as I absorb the material deeply. Thanks for the videos!

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

    Ok, add 1000000 items and you'll see that its shit code.

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

      Hi Ilya. Thanks for the comment. Indeed, this code isn't meant to necessarily scale particularly well. There are lots of off the shelf and built-in solutions for Python already that handle this task much better than this code. The only reason I have it here is that linked lists are a fundamental concept for computer science and often technical interviews. Understanding the inner workings of these things can be helpful, that was my only intent. Good point though!