Tech Unleashed

Wohoo!! We're on YouTube

Wednesday, 20 September 2023

C++ : Lecture 4: Insertion at end in Singly Linked List : Mastering Linked List Made Simple !

 Mastering Linked List Made Simple: Your Easy Guide to Data Structures !


Insertion at end in Singly Linked List Code [C++] :

#include<iostream>

using namespace std;

//Implementation of Node
class Node{
    public:
    int data;
    Node* next;
    
    Node(int data){
        this->data = data;
        this->next = NULL;
    }
};

void insertionAtEnd(Node* &head, Node* &tail, int data){
    Node* newNode = new Node(data);
    if(head == NULL){
        head = newNode;
        tail = newNode;
    }else{
        tail->next = newNode;
        tail = newNode;
    }
}

void print(Node* head, Node* tail){
    Node* temp = head;
    while(temp != NULL){
        cout<<temp->data<<" ";
        temp = temp->next;
    }
    cout<<endl;
    cout<<"Head : "<<head->data<<endl;
    cout<<"Tail : "<<tail->data<<endl;
}

int main()
{
    Node* head = NULL;
    Node* tail = NULL;
    insertionAtEnd(head,tail,30);
    insertionAtEnd(head,tail,40);
    print(head,tail);
    return 0;
}

Hey, thanks for watching our video about Linked list ! In this video we’ll walk you through:

- Insertion at end concept

- Handling subcases in insertion

- Implementation


All codes are available at my GitHub account, check them out here:

https://github.com/shyamkanth/Placements


Check out other videos from DS Revealed playlist: https://www.youtube.com/playlist?list=PLNXqJgOsTCZOB60T9HDhMf_o8RXbNWgqS


Check out our channel here: https://www.youtube.com/@DevelopersByte


Find us at: https://shyamkanth.github.io/


Timestamps:

0:00 Intro

1:20 Insertion at end concept

2:37 Approach

4:10 Step wise implementation

7:35 Handling empty list case

9:58 Handling non-empty list case

13:05 Code

17:50 Outro


About our channel:

Our channel is about Revealing the secrets of Data Structure. We cover lots of cool stuff such as Codes, Concepts and Implementations.

Check out our channel here: https://www.youtube.com/@DevelopersByte

Don’t forget to subscribe!


Follow me on social media:

Get updates or reach out to Get updates on our Social Media Profiles!

GitHub: https://github.com/shyamkanth/

Instagram: https://instagram.com/still_23.6_8

Instagram personal: https://instagram.com/itz_sammmii

No comments:

Post a Comment