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

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

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

  • @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 ปีที่แล้ว +178

    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 ปีที่แล้ว +15

    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 ปีที่แล้ว +23

    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 2 หลายเดือนก่อน

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

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

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

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

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

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

    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.

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

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

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

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

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

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

    You are the best teacher ever. Period.

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

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

    best explanation of linked lisgt ever seen on you tube

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

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

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

    best c++ instructor I have come across

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

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

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

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

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

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

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

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

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

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

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

    Most Underrated Channel ever

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

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

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

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

    best linked list video tutorial i came across

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      You're welcome 🥰

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

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

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

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

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

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

    continue doing all sort of videos your saving lifes

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

    your teaching style i really really perfect

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

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

    The video have added more clarity on the coding experience

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

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

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

    Wow you really explain these concepts well.

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

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

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

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

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

    your teaching technique is great!

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

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

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

    Best teacher ever.

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

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

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

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

  • @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 🤗☺️🤞

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    You are the best in the TH-cam💗

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

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

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

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

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

    You saved my day ma'am.
    Thank you.

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

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

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

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

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

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

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

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

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

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

    Thanks for the valuable content.

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

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

  • @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 22 วันที่ผ่านมา

      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.

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

    Bravo for this very educational tutorial!

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

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

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

    Thanks! Really clear and easy to follow 😃

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

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

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

    Small improvement of InsertAtTheEnd. You could use the next code to inserts the prepared node. While (*head!=NULL) head=&(*head->next); *head=NewNode;

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

    Beautiful explanation! Thank you so much!

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

    i just wanna say thank you u saved me

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

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

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

    Hi Great Lady! Thank you so much!!!

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

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

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

    You are lookin' gorgeous ma'am, your way of teaching is tremendous.
    Love from India😍

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

      hate from bangladash

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

    In the last part of the video ( insert after an element video)
    while we are assigning the "newNode -> next" to previous pointer(newNode -> next = previous -> next)
    why we are writing previous -> next instead of writing only previous like we did in the next line ( previous -> next = newNode)???
    Just had this one doubt...
    Thankyou so much for this video no one made Linked list this much easy to understand.
    Waiting for Trees

    • @mukund.k28
      @mukund.k28 3 ปีที่แล้ว

      In the first line, we were pointing our newNode's pointer to wherever our previous Node's pointer was pointing.
      In the second line, we point our previous node's pointer to newNode because doing "previous->next=newNode->next" would point it right back where it originally was, so the sequence doesn't really change other than the node after newNode has 2 pointers pointing to it.
      For a more clear visual explanation, go to a site called pythontutor, paste your C++ code.

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

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

    thank you so much for your amazing explanation