#6 Linked List Implementation in Java Part 2 | Data Structures

แชร์
ฝัง
  • เผยแพร่เมื่อ 18 ธ.ค. 2024

ความคิดเห็น • 189

  • @LynN-he7he
    @LynN-he7he 6 ปีที่แล้ว +104

    When you move your cursor to paint, can you highlight the cursor? It's hard to follow where you are pointing to.

    • @ajithm2334
      @ajithm2334 4 ปีที่แล้ว +1

      Same point..

    • @rohitroyYT001
      @rohitroyYT001 3 ปีที่แล้ว +1

      Same point.

    • @LazizbekYusupov92
      @LazizbekYusupov92 3 ปีที่แล้ว

      Yeah, the same problem.

    • @vedapriya888
      @vedapriya888 ปีที่แล้ว

      Actually pointer can be seen if we see very carefully.I think it's better to change the background to cream colour so that the pointer would be highlighted more

  • @maya.n
    @maya.n 6 ปีที่แล้ว +56

    You should add return; in the if(index==0) because it is going to continue doing everything after that code and it is going to put the element twice.
    The code should be like this:
    if(index==0)
    {
    insertAtStart(data);
    return;
    }
    Other than that, great video. It helped me a lot. Thanks.

    • @aleksandarmilosavljevic1996
      @aleksandarmilosavljevic1996 5 ปีที่แล้ว +2

      Your comment was very helpfull to me, thanks! :)

    • @maya.n
      @maya.n 5 ปีที่แล้ว

      @@aleksandarmilosavljevic1996 You're welcome. I am glad I could help, but I think in the next video he fixes it and makes it correct.

    • @dawah7556
      @dawah7556 5 ปีที่แล้ว +1

      thanks for help

    • @jefflee738
      @jefflee738 5 ปีที่แล้ว

      you garbage

    • @jefflee738
      @jefflee738 5 ปีที่แล้ว

      just joking

  • @Misdaque
    @Misdaque 3 ปีที่แล้ว +9

    Great Video! No doubt
    Just one improvement we can do in this.
    In insertAt() method try to put the if condition at the beginning of the line and after calling insertAtStart() method put a return statement.
    if(index == 0){
    insertAtStart(data);
    return;
    }
    Edit: I saw in the next video you have made the correction and accepted your mistake. This makes you even greater!

  • @rissandimo
    @rissandimo 5 ปีที่แล้ว +11

    Excellent video, it was very informative! Just to note (for others), in the insertAt(int data ) method, once we check if the index == 0 and if so we pre-append the data. At that point we have to type return; Because if not, the execution will still continue and add the value again in the for loop.

  • @subhamagarwal476
    @subhamagarwal476 4 ปีที่แล้ว +3

    No one can explain better than you.!!Thank you sir ..finally i understood the concept of LL

  • @FaizanKhan-gfaizank
    @FaizanKhan-gfaizank ปีที่แล้ว

    The best video explanation for linkedlist in java so far...

  • @chetanjha6019
    @chetanjha6019 4 ปีที่แล้ว +2

    Sir u are god in teaching

  • @anuragbhattacharjee2708
    @anuragbhattacharjee2708 6 ปีที่แล้ว +12

    put else after the "if" block for the rest of the code of insertAt method or else the added element will get added twice in the list..

  • @venkat4043
    @venkat4043 3 ปีที่แล้ว +2

    at 8:34 , we need to implement the rest of the code in the else block, otherwise, the data will be added at index 0 and as well as index 1

  • @void_godzpower7473
    @void_godzpower7473 5 ปีที่แล้ว +9

    Best explanation of the topic so far, congrats, keep up the great work

  • @learnandearnakashrdpatel6826
    @learnandearnakashrdpatel6826 5 ปีที่แล้ว +2

    Very nice explanation sir I feel very good while seeing this video because how well explained you it make me very clear and because of I watched your video able to make program of linked list feel very proud I pray to continue making this type of video which will help students like me to get knowledge and make them self and knowledgeable person thank you

  • @manavgupta272
    @manavgupta272 4 ปีที่แล้ว

    Sir you are the best teacher of java.

  • @navjhs
    @navjhs 6 ปีที่แล้ว +19

    Great Video... just one thing--- diagram should be crystal clear while explaining or actually change the pointer of drawing pen in your MS paint as that is hardly visible.

    • @amanmunnolli
      @amanmunnolli 3 ปีที่แล้ว

      Yeah, struggled a lot to keep up with the pointer 😅

  • @pradeepweerasinghe4201
    @pradeepweerasinghe4201 2 ปีที่แล้ว +2

    At first it was like rocket science to me😅,After watching these videos several times finally got it,Thank you sir.

  • @nebilgokdemir4527
    @nebilgokdemir4527 5 ปีที่แล้ว +3

    this is the best explanation of Link List thank you for sharing

  • @AishusAura
    @AishusAura 4 ปีที่แล้ว

    Easiest but Efficient explanation...Thanks a lot

  • @brucema4730
    @brucema4730 4 ปีที่แล้ว +1

    Your channel has some really great content, but the way you speak is like playing the whole video in 1.5 of the original speed...still many thanks for the detailed explanation and demonstration of how it works in Java!

  • @AnkitKumar-xp9iv
    @AnkitKumar-xp9iv 5 ปีที่แล้ว +2

    Your explanation is great sir with the diagram which helped a lot in understanding the concept

  • @aaronquitoriano1606
    @aaronquitoriano1606 5 ปีที่แล้ว +11

    Can't see the cursor when you are pointing in paint. :(

  • @HafizurRahman-dr3xe
    @HafizurRahman-dr3xe ปีที่แล้ว

    Your Effort is Absolutely so helpful. Thaks A Lot

  • @swayamprakashsahoo9002
    @swayamprakashsahoo9002 4 ปีที่แล้ว +1

    Thank u sir for kind effort to teach us... I am really happy having understood this part

  • @ashankavindu2409
    @ashankavindu2409 4 ปีที่แล้ว

    Man...you like a God to me.....❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤

  • @mewnine7278
    @mewnine7278 6 ปีที่แล้ว +1

    You Explain Better Than My Professor Thanks

  • @HafizurRahman-dr3xe
    @HafizurRahman-dr3xe ปีที่แล้ว

    We should go always in depth. Thanks a lot

  • @travelnlearn
    @travelnlearn 3 ปีที่แล้ว

    Thanks for this wonderful video. May gbu with lots of success love and life. Keep Rocking

  • @no_more_anymore
    @no_more_anymore 2 ปีที่แล้ว

    @2:22 It's also not necessary to have the code: 'node.next = null;' right?

  • @akshaycoder7919
    @akshaycoder7919 4 ปีที่แล้ว +1

    Thank you sir for explaining in
    Such a simple words

  • @yatinpandey6499
    @yatinpandey6499 4 ปีที่แล้ว +3

    It seriously was very confusing when you were stating the n.next part.
    Spent my 3 straight hours and still didn't got anything after node.next=n.next😶
    Although,Thanks for your efforts sir.
    Love and Respect 🙏🏻💕

  • @raamanujbhattacharya5606
    @raamanujbhattacharya5606 4 ปีที่แล้ว +1

    didn't understand at 7:43 min i.e; n.next=node;

  • @sooriyakumarkarnan7885
    @sooriyakumarkarnan7885 6 ปีที่แล้ว +1

    thank you very much sir
    i like very much your teaching method and your video is very helpful to my programming studies

  • @milaismyname
    @milaismyname 7 ปีที่แล้ว +4

    Perfect explanation, thank you so much!

  • @soumyadebbasu7882
    @soumyadebbasu7882 4 ปีที่แล้ว

    We can also create a parameterized constructor inside Node class to define the data and link part, so we need to write only one line of code, while creating the object, in each of the methods of linked list class.

  • @mindgym4543
    @mindgym4543 5 ปีที่แล้ว +1

    Great video, but we need to handle outofindex error Use below code
    in indexAt method
    for (int i = 0; i < aIndex-1; i++) {
    mTempNode = mTempNode.mNext;
    if(mTempNode== null){
    System.out.println("Please insert valid index!!
    Unable to insert");
    return;
    }
    }

  • @TheSanghamSaga
    @TheSanghamSaga 4 หลายเดือนก่อน

    Hello sir
    In insertAt method for the 0 index we need to write a code
    If (index == 0) {
    node.next = head;
    head = node;
    }
    If we call insertAtStart method then it will create two objects.
    The first object will be created when we call the inserat method and the second object will be created when we call the insertAtStart method from if block.

  • @muhammadwaqar5612
    @muhammadwaqar5612 5 ปีที่แล้ว +4

    Although you've taught very well thanks a lot, but there's a bug in addAt() method, what if someone input index which isn't in the list? there'll be nullPointerException.
    here I've applied my own logic, please check if it's okay? (working fine in IDE)
    void addAt(int i, int value)
    {
    Node node = new Node();
    node.data = value;

    if(head == null)
    {
    head = node;
    System.out.println("List is empty, node added at index 0");
    }
    else
    {
    Node n = new Node();
    n = head;

    while(n.next != null)
    {
    if (index == i-1)
    {
    node.next = n.next;
    n.next = node;
    break;
    }
    else if(i == 0)
    {
    addFirst(value);
    break;
    }
    n = n.next;
    index++;
    }
    if(n.next == null)
    {
    System.out.println("Given index is out of list");
    }
    }

  • @bilalahmed2263
    @bilalahmed2263 4 ปีที่แล้ว +1

    please Clear my point.. why it work as node.next= n.next... why it did't work as n.next=node.next ? in insertatstart method

  • @jasrulzam
    @jasrulzam 2 ปีที่แล้ว

    Hi,
    When you do insert a value at index, n already points to head before for loop, so in the first iteration n would have traversed to index 1 right? I did not understand this....pls helpout

  • @ElevateWithMiranda
    @ElevateWithMiranda 5 ปีที่แล้ว

    thanks so much, far better than my proff

  • @coderbuddy3875
    @coderbuddy3875 4 ปีที่แล้ว +1

    Great explanation at TH-cam !!

  • @kanhaiyasharma5834
    @kanhaiyasharma5834 4 ปีที่แล้ว

    very nice explanation but in inserAt(int index,int data) method we have to add for loop & Node n = head; into else statement otherwise data will be added two times.

  • @amarabd9844
    @amarabd9844 20 วันที่ผ่านมา

    For the insertAtFirst() instead of making all those things we use node.next = head; head = node;

  • @crazylife7902
    @crazylife7902 5 ปีที่แล้ว +1

    Can you use a custom cursor. Its provided by the windows itself. That's the only addition this video now needs. Its really difficult to follow this video without that cursor when it travels of to the right side of the window. If you update this video with the new cursor, please share the link to the new video herewith. Thank you!

  • @zainabissa162
    @zainabissa162 ปีที่แล้ว

    Great explanation Thank you.

  • @nithyalakshmi6033
    @nithyalakshmi6033 19 วันที่ผ่านมา

    Hi sir, i have a confusion on line 51
    node.next = n.next
    node.next should have the address of next node, which is 45, why we are pointing it to 18 which is previous node.
    My understanding here is n refers to 18 node only because of the condition (i

  • @paulz6045
    @paulz6045 4 ปีที่แล้ว +1

    first, you need to implement list.size(), and then check if index > list.size(){ thow new Exeption() }!

  • @kchemutai3483
    @kchemutai3483 2 ปีที่แล้ว

    Thanks so much, best tutorial so far on this topic. One bug on InsertAtIndex, if the user specifies an index out of range like index 12. I have captured it buy inserting the element at the end of the list

  • @bhanuprakashkatika
    @bhanuprakashkatika 2 ปีที่แล้ว

    thank you very much sir for detailed explanation

  • @AllInOne-jg5qx
    @AllInOne-jg5qx 3 ปีที่แล้ว

    You have to put the else block after if and put rest of the code to else block otherwise the added element will be added twice.

  • @fanforever9916
    @fanforever9916 2 หลายเดือนก่อน

    wow!!!. thank you so much. god bless you.

  • @kristystrives6979
    @kristystrives6979 4 ปีที่แล้ว

    More useful than my lecturer

  • @manojkumarvavilapalli3192
    @manojkumarvavilapalli3192 3 ปีที่แล้ว

    ni8 entha track chesina okka point ekkado miss ipothuna.... Mee video okka 5min chusa, path clear ipoiendi.... Thank you bro

  • @ehabwa1167
    @ehabwa1167 4 ปีที่แล้ว

    YOU'RE FANTAAAAAAASTIC!!!
    Big thnx

  • @carolinaestrada3509
    @carolinaestrada3509 5 ปีที่แล้ว

    Can you explain when you did -------> node.data = data ? Is this similar to when you have setters and put [ this.variable = variable; ] ? I didn't know you could put an, Object.AnotherDataType, to equal that data type (AnotherDataType). Can you explain what node.data does specifically please?

  • @anduempire4373
    @anduempire4373 3 ปีที่แล้ว

    In insertAt method, if given index is 3 and only one node in LinkedList then what happens??
    in this scenario user inserted at 3rd index but element added at 1st index
    so handle this scenario as well.

  • @bhaskarwhitebox
    @bhaskarwhitebox 6 ปีที่แล้ว

    special thanks to your diagrammatically representations.

  • @rajasekar4853
    @rajasekar4853 7 ปีที่แล้ว

    It's helps for me a lot thanks sir I am waiting for sequences of this series

  • @mohammedmudassirkhatri6871
    @mohammedmudassirkhatri6871 5 ปีที่แล้ว +1

    why are we not making an object of head just like node ???

  • @sourabhsharma2649
    @sourabhsharma2649 5 ปีที่แล้ว +1

    sir please upload videos of doubly and circular linked list

  • @shekhrussel6304
    @shekhrussel6304 5 ปีที่แล้ว

    Ur videos r so much helpful for bttr understanding😍👍

  • @narendra9903
    @narendra9903 6 ปีที่แล้ว +4

    Am confused..At 7.42 you wrote node.next = n.next . means next element of n is assigned to node.cant we write node= n.next?

  • @AvinashKumar-uz9fq
    @AvinashKumar-uz9fq 5 ปีที่แล้ว +1

    What if Index is more than the number of element. NullPointerException will be thrown. So code is incomplete for method insertAt().

    • @crateer
      @crateer 5 ปีที่แล้ว

      This is a tutorial and NOT a complete follow along replecation of any Collection
      Also what you are saying is literally a maximum of 2 lines of extra code to implement.

  • @suchitragiri4546
    @suchitragiri4546 4 ปีที่แล้ว

    Your videos are awesome!

  • @Akichu95
    @Akichu95 6 ปีที่แล้ว +1

    I have the same code as you, however when i assign position (0, 33)
    The data will be entered twice at the start before displaying the rest of the list
    Edit: the Node n = head and for loop should be in an "else" statement after the if statement

    • @kevinwu5017
      @kevinwu5017 6 ปีที่แล้ว

      please read Ben Trono's reply.

    • @vishu194
      @vishu194 6 ปีที่แล้ว

      that is bcoz sir forgot to write the return statement inside if statement where we comparing the 0 with index. you just write this --> return; after calling the method insertAtStart(); your problem will be solved then.

    • @crateer
      @crateer 5 ปีที่แล้ว

      return; or else

  • @joschaweiss312
    @joschaweiss312 6 ปีที่แล้ว

    Very nice video, it was very helpful! Don't forget the three lines after the method after the else ;)

  • @maheshbabumeruva4968
    @maheshbabumeruva4968 10 หลายเดือนก่อน

    Why are you not using linked list class in util package? It's very simple to perform all those operations right? No need to write this much of code, Is there any reason?

  • @demdimi9316
    @demdimi9316 4 ปีที่แล้ว

    Great explanations man.

  • @tanvirkazirocks
    @tanvirkazirocks 2 ปีที่แล้ว

    With all respect, we have to put the remaining code in the else block for insertAt() method after if condition

  • @khyatimamaniya7155
    @khyatimamaniya7155 6 ปีที่แล้ว

    Hey!! I have one doubt,how do you access index of any node as you already said linkedlist doesn't always be in sequence so how this index is in sequence and how do u know the index of any node , as far as i know if we want to insert at any position we provide info of data i.e after 18 insert should be done or after any other node that means we are providing data, i don't understand in linked list how this index can come than what is the diff between this and array if we'll provide index?????

  • @sharathkalikota3727
    @sharathkalikota3727 4 ปีที่แล้ว

    already we have inbuilt functions to add,delete etc....Then what is the use to write our own class as LinkedList I mean What is the use to write LinkedList classs rather thn using inbuilt class @Telusko

  • @pratiksaha4199
    @pratiksaha4199 6 ปีที่แล้ว

    i'm getting an exception for the show method.
    public void show() {
    Node n = head;
    while(n!=null) {
    System.out.println(n.data);
    n=n.next;
    }
    System.out.println(n.data);
    }
    Can you suggest some other alternatives?

    • @ayushbagwari3496
      @ayushbagwari3496 6 ปีที่แล้ว

      Write node instead of n in while block

  • @tanujaks504
    @tanujaks504 3 ปีที่แล้ว

    i didn't get can you explain this LinkedList topic slowly, actually i know about the working of linkedlist but i didn't get how to implemets in coding part..

  • @chandravideo
    @chandravideo 7 ปีที่แล้ว

    sir
    if we write IF condition for an insertAt function in the beginning, then excess node created in insertAt function won't be happening.

  • @Monawa3atCOM
    @Monawa3atCOM 5 ปีที่แล้ว

    NOTICE: u must put FOR boucle at else of (if index==0) because if you dont it will be dublicate the same number on pos 0 and 1....am i right???????

  • @palashkhatri7820
    @palashkhatri7820 4 ปีที่แล้ว

    Really nice explanation, Just paint representation can be lill more clean.

  • @ayushigolwara
    @ayushigolwara 4 ปีที่แล้ว

    There is one issue in the code in inserAt method, if input is 0th position u need to add return in the if condition otherwise the data will be added to the list twice
    if(index==0)
    {
    insertAtStart(data);
    return;
    }

  • @sudhakarreddy5781
    @sudhakarreddy5781 4 ปีที่แล้ว

    Hello Navin, can you make a video by implementing this methods in recursive way.
    for example prependElement(int value)-- recursively.

  • @sachinkumarsingh538
    @sachinkumarsingh538 6 ปีที่แล้ว

    hi sir
    thanks for such nice video
    but i would like to add a point what if someone is trying to add at a particular index and the head value is null or if the passed index is greater than available data in the list

  • @ashutoshsahoo9629
    @ashutoshsahoo9629 3 ปีที่แล้ว

    If I am using the insertAtStart() multiple times, it's not executing

  • @saunakpaul4466
    @saunakpaul4466 6 ปีที่แล้ว

    in insertatstaRt method,
    Why did you code n.neXt=null
    ?

    • @vishu194
      @vishu194 6 ปีที่แล้ว

      it doesn't require to write that part. Sir just wrote that code just for the sake of understanding.

  • @micoruzic5548
    @micoruzic5548 5 ปีที่แล้ว

    great video you helped me a lot but please change your cursor when you go to paint it's hard to follow it
    thanks

  • @vishnuv918
    @vishnuv918 3 ปีที่แล้ว

    Please upload all data structures in java sir

  • @chinnimurali7340
    @chinnimurali7340 6 ปีที่แล้ว

    How to display node.data and node.next in main method??

  • @johncrowley5958
    @johncrowley5958 5 ปีที่แล้ว

    My code is the same as yours. My insert at end is non-static, but for some reason my insertmiddle and insert start have to be static! Why is this? I feel like its not correct. I'm using JDK 11

  • @isharaperera419
    @isharaperera419 5 ปีที่แล้ว

    Really helpful Reddy!

  • @rakeshp8582
    @rakeshp8582 4 ปีที่แล้ว

    Hi , i did same thing what you did in your video...i have tried to add element to 0 index, but, it prints the element 0, 1 index

  • @mindgym4543
    @mindgym4543 5 ปีที่แล้ว

    Complete indexAt method, however according to my knowledge, suggestions appreciated:
    void insertAt(int aIndex, int aData) {
    Node mNode = new Node();
    mNode.mData = aData;
    mNode.mNext = null;
    if (aIndex < 0) {
    System.out.println("Please provide proper positive index");
    } else {
    if (head == null) {
    if (aIndex == 0) {
    head = mNode;
    } else {
    System.out.println("Linked list is empty, can not insert at " + aIndex);
    }
    } else {
    if (aIndex == 0) {
    insertAtFirst(aData);
    } else {
    Node mTempNode = head;
    for (int i = 0; i < aIndex - 1; i++) {
    mTempNode = mTempNode.mNext;
    if (mTempNode == null) {
    System.out.println("Please insert at valid index!!
    Unable to insert");
    return;
    }
    }
    mNode.mNext = mTempNode.mNext;
    mTempNode.mNext = mNode;
    }
    }
    }
    }

  • @rahulborule8619
    @rahulborule8619 3 ปีที่แล้ว

    How to delete a node at specific index?

  • @dinkarinjosh
    @dinkarinjosh 5 ปีที่แล้ว

    he explains in the next video, there is a slight mistake. the if loop if checking index ==0, should accompany with an else, else the element gets added twice.

  • @random-0
    @random-0 5 ปีที่แล้ว +1

    return should be added in if(index==0)

    • @ArrennBaral
      @ArrennBaral 5 ปีที่แล้ว

      Yeah, I was getting two data printed, thanks

  • @maheshanvekar
    @maheshanvekar 6 ปีที่แล้ว

    Thank You for the explanation but can we have some real time scenarios for the linkedlist usage

  • @chethanprabhu4475
    @chethanprabhu4475 6 ปีที่แล้ว

    you wrote if index=0 then call insertatstart...if so then rest of code you have to put in else block right? correct me if im wrong

    • @crateer
      @crateer 5 ปีที่แล้ว

      You don't have to actually(generally), the way he wrote it means it checks if index = 0, then keeps on going with the rest of the code as usual
      In this case, he should have put "else" in there, yes - because the code would keep running and add the node twice

  • @chinmaysoni4416
    @chinmaysoni4416 5 ปีที่แล้ว

    great explanation sir

  • @akshitdbz9530
    @akshitdbz9530 6 ปีที่แล้ว

    Sir
    Node with data 55 shd hve reference of node with data 45
    How are we doing that?

  • @shreyanshnigam620
    @shreyanshnigam620 4 ปีที่แล้ว

    I m getting a exception main thread i dont know how i m so confused help me here Exception is
    java.lang.NoClassDefFoundError

  • @adityasinghrajawat7344
    @adityasinghrajawat7344 4 ปีที่แล้ว

    Great Explanation Sir but when we are inserting at start we can just use "head.data=data".I have tried ands its working correct me if I am wrong.

    • @sydefx5451
      @sydefx5451 4 ปีที่แล้ว

      then you previous head data

  • @vibhutisharma3848
    @vibhutisharma3848 5 ปีที่แล้ว

    pls make video on circular and doubly linked list

  • @shivashanker4488
    @shivashanker4488 7 ปีที่แล้ว

    Sir, could you provide any soft copy related linked list for extra information through description If it is possible only.

  • @sathish8572
    @sathish8572 4 ปีที่แล้ว

    insert at index 0 the method adding twice because before if condition a node as been created and data as been assigned and after if condition again once again data as been inserting due to insert at start!!!

  • @MrTauquir
    @MrTauquir 6 ปีที่แล้ว

    Its outstanding video but pace of presentation should be little slow.

  • @javalearningandearning1629
    @javalearningandearning1629 2 ปีที่แล้ว

    Please use other curser instead of point. The explanation is too good.