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

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

КОМЕНТАРІ • 342

  • @CodeBeauty
    @CodeBeauty  3 роки тому +66

    📚 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 роки тому +2

      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 роки тому +171

    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.

  • @SavageScientist
    @SavageScientist 3 роки тому +22

    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

  • @sarwat3552
    @sarwat3552 2 роки тому +49

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

  • @doublej118jc
    @doublej118jc 2 роки тому +18

    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 роки тому +13

    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.

  • @beegameplay2.082
    @beegameplay2.082 3 роки тому +16

    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 🇵🇰❤️❤️

  • @phantom_dorex_4573
    @phantom_dorex_4573 Місяць тому +1

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

  • @Reem-du7sd
    @Reem-du7sd 2 роки тому +3

    I never comment on UA-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!

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

  • @lamprosgiannopoulos8489
    @lamprosgiannopoulos8489 3 роки тому +5

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

  • @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 2 роки тому

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

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

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

  • @maxdemendieta1426
    @maxdemendieta1426 Рік тому +2

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

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

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

    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.

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

    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.

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

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

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

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

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

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

  • @omeralsumeri5819
    @omeralsumeri5819 2 роки тому +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.

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

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

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

    your teaching style i really really perfect

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

    This definitely helps me to understand the linked list.
    I searched a video on UA-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.

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

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

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

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

  • @BasitAli-uk6fj
    @BasitAli-uk6fj Рік тому +1

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

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

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

    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!

  • @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. 👌😊

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

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

  • @NaveenKumar-oz6wp
    @NaveenKumar-oz6wp Місяць тому

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

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

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

    best explanation of linked lisgt ever seen on you tube

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

    You are the best teacher ever. Period.

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

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

    best linked list video tutorial i came across

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

    best c++ instructor I have come across

  • @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.❤♥💗💓

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

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

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

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

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

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

      yess I will 🤗☺️🤞

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

  • @jeromeswizz4917
    @jeromeswizz4917 10 місяців тому

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

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

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

  • @dwivedys
    @dwivedys 3 місяці тому +1

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

  • @nasirhammi
    @nasirhammi 3 місяці тому

    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 ❤❤❤❤❤

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

    Wow you really explain these concepts well.

  • @ChupoCro
    @ChupoCro 2 роки тому +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.

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

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

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

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

    Most Underrated Channel ever

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

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

  • @Asterics.
    @Asterics. 5 місяців тому

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

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

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

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

    continue doing all sort of videos your saving lifes

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

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

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

    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.

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

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

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

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

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

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

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

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

    Thanks for the valuable content.

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

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

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

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

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

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

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

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

    Ma'am please cover all data structure concepts. You are doing great ma'am. Love and support from India. Thank you❤

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

      Thank you, I will. Love for India ❤️

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

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

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

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

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

    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 🥺

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

    your teaching technique is great!

  • @mastermax4658
    @mastermax4658 10 місяців тому

    You are the best in the UA-cam💗

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

  • @michaelfgondwe
    @michaelfgondwe 5 місяців тому

    The video have added more clarity on the coding experience

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

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

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

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

  • @funnyvideos-mv5ec
    @funnyvideos-mv5ec Рік тому

    i just wanna say thank you u saved me

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

    You are the best! ❤❤
    Thank you 🥰

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

    Best teacher ever.

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

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

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

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

  • @skill-f-mahi
    @skill-f-mahi 2 роки тому

    You saved my day ma'am.
    Thank you.

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

    Thanks! Really clear and easy to follow 😃

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

    Great Explanation

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

    Thanks, that was very helpful!

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

    Beautiful explanation! Thank you so much!

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

    thank you for such a hard work

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

    Bravo for this very educational tutorial!

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

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

    This video is super helpful and informative

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

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

    Hi Great Lady! Thank you so much!!!