Design a Singly Linked List

Поделиться
HTML-код
  • Опубликовано: 6 ноя 2024

Комментарии • 21

  • @HermesSoilder
    @HermesSoilder 5 месяцев назад +3

    Setting the head to an empty value really makes a huge difference

  • @hypermeero4782
    @hypermeero4782 Год назад +6

    BRING BACK THE OLD THUMBNAIL

  • @alexzan1858
    @alexzan1858 2 месяца назад +2

    I dont understand part 6:28. If we want to insert a new head. Shouldnt new_node.next = self.head , and self.head = new_node . So we first point the new head to the old head node, then we assign it as the new head. But now you are inserting a node between the old head and the old heads next node ... ?

    • @acmethunder
      @acmethunder Месяц назад

      Yup. That was frustrating me too when the tests were failing.

    • @EdenObengNanaKyei
      @EdenObengNanaKyei Месяц назад

      we are not doing new_node.next = self.head because remember self.head is the dummy node before the actual head of the linked list. So to point the new node to the old head you have to do new_node.next = self.head.next( this gives the old head)

  • @anonymoussloth6687
    @anonymoussloth6687 Год назад

    How did you make a leetcode-like editor on your website? What libraries/tools did you use?

    • @NeetCodeIO
      @NeetCodeIO  Год назад +2

      Will make a video on it soon!

    • @anonymoussloth6687
      @anonymoussloth6687 Год назад

      @@NeetCodeIO can you also mention how u made the node/tree editor on your website for the roadmap?

    • @ajinkyax
      @ajinkyax 9 месяцев назад

      @@anonymoussloth6687 angularjs node graph library

  • @grandparick3176
    @grandparick3176 Год назад

    Well I hope my data structure college course would be helpful xD. But we did it using struct in c++ and not class but I guess the same idea could be applied here.

  • @mohamedelgaili9895
    @mohamedelgaili9895 9 месяцев назад +1

    I really need your help on knowing where I can learn the fundamentals of understanding this code. Like, I know the syntax for Python and loops and all that but I don't know anything about classes or objects or even how you could do self.head.next at 4:10. Could you guide me on where I could learn those fundamentals? Any help is appreciated, thank you.

    • @Kirbylini
      @Kirbylini 8 месяцев назад

      Learn about classes, superclass/parentclass and then subclass/childclass. Along with inheritance and polymorphism. 1 month late so maybe you already got your answer but if not there's lots of guides or ask chatgpt (what I did at least)

  • @fabersoaks4975
    @fabersoaks4975 8 месяцев назад

    complexity of appending at ending of the single linked list is On ?

  • @t-m5678
    @t-m5678 Год назад

    This is great. Thanks.

  • @markokafor7432
    @markokafor7432 Год назад

    Nice video. Why are you pointing the tail to the head? self.tail = self.head

    • @Applecitylightkiwi
      @Applecitylightkiwi Год назад

      Depends on scenario but basically if you create a new node
      Self.head = new node
      Self.tail = self.head
      The second line means that they are both pointing to the new node
      You could also say self.tail = new node basically in this scenario its the "same"

    • @hdot2613
      @hdot2613 7 месяцев назад

      It means we have a dummy value regardless if we're adding/removing from the start or end of a potentially empty linked list.

  • @sharmagkachannel
    @sharmagkachannel 3 месяца назад

    when doing the get method in the single linked list, are we not counting head and tail when considering the index in the linked list as per your code if I pass 0 to the get function
    I will be getting the node value next to the head and not the head.
    @NeetCodeIO please do reply

    • @frescosmalls
      @frescosmalls 3 месяца назад +2

      He keeps the dummy head node and never removes/replaces it. I'm not sure why, it seems silly to keep this dummy node (or to even initialize with a dummy node in the first place). So yes, when creating your get method you should start the pointer at the self.head.next as he shows at 3:33
      Personally, I think this entire design is flawed in keeping the dummy nodes that serve no real purpose. We should just be initializing an empty list, and if you go to insert a head or tail when there is no current head or tail, both are set to the new node or return some error stating there is no head/tail. Maintaining the dummy node just adds another variable to consider when making changes to the LinkedList that are unnecessary. Interviewers likely would appreciate seeing you handle edge cases such as this anyway.