How to insert a new node in a linked list in C++? (at the front, at the end, after a given node)

แชร์
ฝัง
  • เผยแพร่เมื่อ 8 ม.ค. 2025

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

  • @CodeBeauty
    @CodeBeauty  3 ปีที่แล้ว +69

    📚 Learn how to solve problems and build projects with these Free E-Books ⬇️
    C++ Lambdas e-book - free download here: bit.ly/freeCppE-Book
    Entire Object-Pascal step-by-step guide - free download here: bit.ly/FreeObjectPascalEbook
    🚀📈💻🔥 My Practical Programming Course: www.codebeautyacademy.com/
    Experience the power of practical learning, gain career-ready skills, and start building real applications!
    This is a step-by-step course designed to take you from beginner to expert in no time!
    💰 Here is a coupon to save 10% on your first payment (CODEBEAUTY_YT10).
    Use it quickly, because it will be available for a limited time.
    #include
    using namespace std;
    class Node {
    public:
    int Value;
    Node* Next;
    };
    void printList(Node* n) {
    while (n!=NULL) {
    cout Value Next;
    }
    }
    int main()
    {
    Node* head = new Node();
    Node* second = new Node();
    Node* third = new Node();
    head->Value = 1;
    head->Next = second;
    second->Value = 2;
    second->Next = third;
    third->Value = 3;
    third->Next = NULL;
    printList(head);
    system("pause>0");
    }

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

      di si? pozz iz tz---kakvo je vrijeme u Mostaru?

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

      Thanks for your videos you’re an amazing teacher. I’m paying for university but I learn better from your videos

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

      Why not all the code at the end.

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

      When we are inserting a node after specific node, why are we not passing address of previous node in the function insertAfter?

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

      Share over all code

  • @mdmobarokrubel2635
    @mdmobarokrubel2635 3 ปีที่แล้ว +182

    Please please please cover all the data structure and algorithm (DSA) topics. Loved all your C++ videos but if you cover DSA topics as well, hundreds and thousands will find help.

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

    You can explain very thoroughly . Hands down this is by far the best linked list video I've ever come across TH-cam. Please upload more such content, you have a great skill of expressing your ideas easily to people, best wishes

  • @doublej118jc
    @doublej118jc 3 ปีที่แล้ว +17

    I've watched a few of your videos and In one of them you mentioned your life-long dream is to be a teacher. You should definitely pursue that dream you're a VERY good teacher!

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

    You are the best Code teacher I've come across Miss Saldina.
    Teachers like you are what we need.
    Taking us step by step through concepts with very detailed explanations and implementations.
    You are just outstanding. Truly impressive work.🥳.
    You are appreciated all the way from South Africa.

  • @SavageScientist
    @SavageScientist 3 ปีที่แล้ว +25

    i love how you pasted the source code right in the comment now thats accessibility

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

      Lol Raw is the new thing

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

      When we are inserting a node after specific node, why are we not passing address of previous node in the function insertAfter?

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

      @@fly4me2night its Savage

    • @Aurora-bv1ys
      @Aurora-bv1ys 3 หลายเดือนก่อน

      @@fly4me2night insane

  • @beegameplay2.082
    @beegameplay2.082 3 ปีที่แล้ว +17

    I liked your teaching style you are making your all viewers as a good coder. You clear all concepts easily speaking in english but others not and thats very helpful for all kinds of viewers. Love from Pakistan 🇵🇰❤️❤️

  • @Reem-du7sd
    @Reem-du7sd 2 ปีที่แล้ว +3

    I never comment on TH-cam videos but omg YOU ARE A LIFE SAVER! I've always found difficulty in coding, but thanks to your videos I am slowly gaining confidence. Forever grateful for all the knowledge you are sharing with us!❤

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

    Great Work !The best teacher I've come across on yt so far!

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

    I was so confused about how to insert an node in the linked list but after watching this video I am not confused anymore. Your way of explanation is so good.

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

    I absolutely love these videos! Learning Data Structures and Algorithm implementations in C++ (as well as becoming more fluent with the language). Will be watching much more, thanks for the awesome content, you're a great teacher :D

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

      Welcome, I'm glad 😃😃

  • @King-un8ui
    @King-un8ui 3 ปีที่แล้ว +9

    I can't understand my professor at all, and your explanation is amazing. Thank you for this two linked list tutorials!

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

      🤗🤗🧡

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

      @@CodeBeauty When we are inserting a node after specific node, why are we not passing address of previous node in the function insertAfter?

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

      @@aspabhi31 you will only need pointer to pointer when you want to change the value of the pointer, like in the insertAtTheFront(), you will make the *head to point to the newNode.

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

      @@sieghart1931 isn't should be change the address of pointer?

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

    Perfect explanation of inserting a node between two nodes. It took me what feels like forever to understand linked lists, but this helped a lot.

  • @hicarodanrlley149
    @hicarodanrlley149 3 ปีที่แล้ว +10

    I really appreciate your course about OOP. Thank you so much for that masterpiece work

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

      When we are inserting a node after specific node, why are we not passing address of previous node in the function insertAfter?

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

      @@aspabhi31 We just have the head node address, we have to loop through the linked list until the previous node. That's why we have O(N) for inserting after because we need to loop until the previous node and after that we insert our node

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

    You’re a life saver, your videos are so clear and easy to understand, thank you so much for creating content like this

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

    I love your teaching style because it has made me to fall in love with C++ something I used to fear.

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

    im so happy that you existed! you help me alot through my coding journey honestly you are better than my professor

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

    I spent one month learning this in my class and here everything is explained in just 30min... GOOD JOB !!!

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

    You are the best teacher ever. Period.

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

    I don't write comments much but i am writing this to thank you for being my savior in my hard times such as my exams lol, you are lliterally the only coder on youtube who i have found to be so descriptive. Thank you for being on youtube .

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

    Love your video! I spent the whole day yesterday and tried to understand what the linked list is. All other videos was confusing but now with your help and I totally get it! Thank you so much!!! Keep it up for the excellent work!

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

    Just in time, i just finished the previous video and boom... another one. You're a speedrunner! 😜

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

    You're currently saving me for my head assignment (a family tree). Thank you!

  • @BasitAli-uk6fj
    @BasitAli-uk6fj 2 ปีที่แล้ว +1

    its very helpful video to every student whose want to learn DSA....i learn in just a 1 hours .....thanks allots from pakistan 👍....

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

    best c++ instructor I have come across

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

    Thank you so much, I love the way you teach and explain everything perfectly. I hope the best for you in all of your goals and pursuit of happiness.

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

    Your explanations are the best, this is what I was looking for all this time

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

    u explain things 10 times better tthan any professor or textbook has ever for me

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

    Please keep going. Most people give up making Yt videos. Very articulate explanations. I watched a few of your videos 7-8 months back. The delivery and clarity has improved a lot. And happy women's day. 😎

  • @phantom_dorex_4573
    @phantom_dorex_4573 5 หลายเดือนก่อน +1

    Thank you so much sister for the crystal clear explanation with each line of the code 🎉👍🙏

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

    This definitely helps me to understand the linked list.
    I searched a video on TH-cam that is spoken in my mother language but all of them were much difficult than yours.
    In addition, they were too generalized from the beginning, but this point-by-point lecture makes me understand well.

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

    best explanation of linked lisgt ever seen on you tube

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

    I need to thank ou so much!! I'm on university and have to make a test about data structures in c++, but I had no knowledge of c++ before, only python and a little bit of c, so I first watched your full course video and now I am watching this one, you are amazing!! Also I'm brazilian and your english is absolutely perfect!

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

    This is a excellent presentation in simple understandable English.
    The topic was nailed.
    Thank you

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

    Your videos are a refresher to me, I learned these concepts with Pascal a few year ago for the university and I forgot it. Thanks!

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

    Not Gonna Lie...
    You did a grate job explaining it

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

    was so passionate about coding I'm just a young teenager....I also learnt c++ from an internet website for free....but as my exams approached my mom took my laptop for 2 months ....now I'm watching your that whole c++ video I was very sad about what happened but I'm back again!
    Thanks
    Hope you make more cources for different programming languages as well....

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

    Hey Saldina! your videos have really helped me through uni the last 2 days, would you please cover double and circle LL? and defintley some sorting algorithims, keep up the good work!

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

    I found your explanation easiest. I am very happy with your teaching style.

  • @royalty-024
    @royalty-024 ปีที่แล้ว

    You have been so helpful. You explain in such a simple clear way and so straight to the point . I love your videos.❤♥💗💓

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

    I wish I had known about this channel during my high school. Data Structures were something that made me get frustrated and unlinked a lot of my brain cells. But it's never too late to learn. Thanks for this video. 👌😊

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

    Your explanation skill is great. Loved how you didn't start from a very complex way to implement a linked list✨️

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

    your teaching style i really really perfect

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

    Just a suggestion especially on data structures. It would be much easier or most peaple to have some graphics. Linked lists, binary trees and so on are hard to explain with just your hands. :-) Thanks for your good work!

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

    Ma'am please cover all data structure and algorithm topics and also it would be very helpful if you give some standard practice questions on each topic, as homework and explain those practice questions in a new video.

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

    Wow you really explain these concepts well.

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

    best linked list video tutorial i came across

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

    continue doing all sort of videos your saving lifes

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

    Your explanation is the simplest and best..thankyou for the good work

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

    Amazing explanation, you have made this very simple and easy to understand. I was facing issue in understanding the insertion operation in linked list. Thanks for this.

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

    Explain in such way.. Oh my god... So niceeee.. thanks mam

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

    remarkable piece of Code especially the detailed explanation line by line , thank you So much.

  • @NaveenKumar-oz6wp
    @NaveenKumar-oz6wp 6 หลายเดือนก่อน

    Superb explaination, thanks for much more clarification in a specific manner

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

    Thanks Saldina, You made it very easy for us to understand these topics. Once again big thanks.

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

    I just discovered this channel - as a fellow female software engineer, it is so awesome to see a woman making coding videos!! ❤

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

    beautiful explanation maam!I have gone through various linked list videos ...your video has no match honestly!so glad that I came across this ytchannel...and I must mention that u look beautiful as well maam

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

    your teaching technique is great!

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

    This video made linked list far more easier to understand. Great work🔥

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

    You’re an amazing teacher. Thank you for your content I really appreciate it.

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

    Most Underrated Channel ever

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

    Thanks a lot. One of the best tutorials I've watched!

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

    you just save my last assignment! Thank you!, you are such good teacher!

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

    You have done an exemplary job!!! .God bless.
    Lifesaver.

  • @dwivedys
    @dwivedys 7 หลายเดือนก่อน +1

    These pointers -- are treacherous -- there’s no other way of saying this …thank you for your lovely explanation as always…

    • @CodeBeauty
      @CodeBeauty  7 หลายเดือนก่อน

      You're welcome 🥰

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

    great explanation, thank you!
    love the outline in comments before you started coding in detail

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

    Hello ! Your lectures are very useful. Can u make more about Dsa like tree, graph etc. Your vedios are more understandable.

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

      yess I will 🤗☺️🤞

  • @nasirhammi
    @nasirhammi 8 หลายเดือนก่อน

    God bless you. Thank you so much for the very good explanation

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

    Ma'am keep posting videos on Data Structures & Algorithms . Really love your way of teaching. Keep growing ma'am ❤❤❤❤❤

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

    Best teacher ever.

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

    Thanks a lot! One question: Why didn't you use pass-by-reference using pointers while implementing the last insertAfter function? You used it in the first two but not in the last one, that confused me a little bit. Other than that, I understood the topic very well. Your teaching is excellent.

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

      I think that is because the insertAfter function does not use head node, so you can easily get the address from the previous node since they are stored in the Next. With the first two functions the address of the head is not stored in any of the node so passing by reference make things easy. I don't know if this answers your question but I hope it make sense.

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

    That's a very clear and excellent video on linked lists.

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

    I had a hard times at this but you successfully guided me through 😉

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

    lady. THANK you so much.. you helped me understand this and pass my tests. thank you tahnk you thank you thank you

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

    Your video on LinkedList is super good. Not much tutorial video use C++ to teach LinkedList, and your video are the best. I have a question about why you passing a pointer to pointer in the insertFront and insertEnd function and passing pointer in the insertAfter function.

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

    You are the best in the TH-cam💗

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

    pls i love you thank you so much for your work❤️✨❤️✨❤️✨❤️✨❤️✨❤️❤️✨❤️✨❤️

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

      ❤️❤️🤗

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

    Wow, Saldina thank you very much. I learned about the linked list in my c++ class course but I didn't understand much. Now I saw your video and it helped me a lot. And one more thing can you please make a video/videos about c++ classes using different(separate) files like header file - c++ file - main function file. Thank you in advance.

  • @skill-f-mahi
    @skill-f-mahi 3 ปีที่แล้ว

    You saved my day ma'am.
    Thank you.

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

    Hey wassup I'm your New Subscriber.. I came to your channel After a Video About The Oops Concept in
    C++ .

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

    Thanks for the valuable content.

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

    thank you a lot, it really help me for a full comprehension of the topic. Namaste

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

    I like your videos because they help me to understand a new concept step by step. One quick question: I think the insertAtTheFront() and insertAtTheEnd(), the first parameter can be just *head, and no need to use **head?

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

    sorry if I sound dumb, but im unable to understand the use of pointers and addresses in complex programms, I dont understand why we are sending only "head" as parameter when displaying the linked list 2:47 , while adding element in the start and end, we send "&head" as parameter 5:09 20:19 and for adding an element in between two nodes, we send "head" as parameter as well 29:04 .

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

    Beautiful explanation! Thank you so much!

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

    Please take live lecture if possible so that we can ask questions in live chat 🙏🙏🙏 by the ways you are the best teachers for beginners 🥺

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

    For the function insert, why you should use two ** after the Node? For example
    void InsertAtFront(Node**, int new_value)

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

    Hehe, there is quite a lot going on with using pointer to pointer + sending a pointer by reference and Saldina of course knows it :-) Many asked why the address of pointer is used when inserting the node at the front. Here is another way of doing the same which might make it more understandable:
    Node* insertAtFront2(Node* n, int val) {
    Node* newNode = new Node;
    newNode->value = val;
    newNode->next = n;
    return newNode; // return pointer to a new head element
    }
    The node in front of the others is now inserted by:
    head = insertAtFront2(head, 201);
    Since the head (which is pointer to Node) variable has to be changed after inserting a new node in front of the others, the function returns a pointer to a new Node which is then used to update the head variable. Saldina used a function returning void and that's why she had to use another way of updating the head pointer outside of a function - which was to send the address of a pointer (a pointer to a pointer) as a parameter so she could update it by just dereferencing.
    In my example there isn't a way to update the head pointer by dereferencing the n variable because here n is sent by value and the function is working with the local copy of the head pointer. That's why I had to declare the function returning a pointer to Node and to assign that value after returning from the function.

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

    live long life, thank you my sister, super linked list vedio tutorials

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

    Thanks! Really clear and easy to follow 😃

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

    Bravo for this very educational tutorial!

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

    The video have added more clarity on the coding experience

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

    Great video!! This helped me with a college class where my professor assumes everyone knows this and refuses to teach it loll. Thanks!

  • @rmarti5163
    @rmarti5163 11 หลายเดือนก่อน

    @19:14 I don't understand how the while loop keeps iterating through pointers rather than just the the *head. Could you please explain?

  • @funnyvideos-mv5ec
    @funnyvideos-mv5ec ปีที่แล้ว

    i just wanna say thank you u saved me

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

    Hi Great Lady! Thank you so much!!!

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

    Finally, I got the topic in my mind :). But I am getting little confused on using the pointer to pointer variable while declaring the function. I know about pointers well as I have watched your pointers playlist as well. But I am still in a bit of confusion.

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

    Your code is more C-Style than modern C++. Maybe you can do video on how to refactor this code?

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

    the 100 comment!
    Thanks Saldina, I really appreciate all your effort
    there is something that I do not understand
    why does insertAtFront receive the addres of the pointer (&head)? why is not enough to input just the pointer (head)?
    Thanks teacher Saldina!

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

      I've been working on this example several hours by now, I think I've acomplished some graps at pointers. Thanks Saldina, I am understanding more about pointers, they can be hard!
      answering my own question, it is needed the address of the ptr so you can know where it is, so you pass its address, but to store an address you need a ptr, so it is stored in a ptr, but, the variable you are working with it is already a ptr, so it is needed a ptr to a ptr

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

    I’ve a question about the first parameter of method insertAfter. Why do you use just * ? In my opinion, the previous node is a pointer and the new node is a pointer too. So, why should we use ** ?

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

    structure and algorithm (DSA) topics,love your new look