Tech Unleashed

Wohoo!! We're on YouTube

Wednesday, 20 September 2023

C++ : Lecture 3: Insertion in Singly linked list : Mastering Linked List Made Simple !

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


Insertion at Beginning 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;
    }
};

//Insertion at begining
void insertAtBeginning(Node* &head,Node* &tail, int data){
    // Creation of new Node
    Node* newNode = new Node(data);
    // CHeck if the list is empty
    if(head == NULL){
        head = newNode;
        tail = newNode;
        return;
    }
    newNode->next = head;
    head = newNode;
}

// Traversing the list
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;
    insertAtBeginning(head,tail,10);
    insertAtBeginning(head,tail,20);
    print(head,tail);
    return 0;
}

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

- Operations in linked list

- Cases and Subcases of operations in linked list

- Insertion at beginning in Singly linked list


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

0:56 Operations in Linked list

2:23 Concept of insertion

4:00 Concept of deletion

4:56 Concept of traversal

6:18 Operation of Singly linked list

7:14 Cases of operations of SLL

8:47 Concept of insertion at beginning in SLL

10:32 Concept of insertion at end in SLL

11:21 Concept of insertion at position in SLL

14:48 Subcases of operation of SLL

19:45 Insertion at beginning in SLL

40:30 Implementation

43:10 Code

54:00 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