Linked-List

Introduction to Linked list

A Linked List is a linear data structure where elements (called nodes) are stored in memory non-contiguously, and each node points to the next node using a pointer.

Key Properties

Types of Linked-list

Example in C++


#include 
using namespace std;

// Node structure
struct Node {
    int data;
    Node* next;
};

// Function to print the linked list
void printList(Node* head) {
    Node* temp = head;
    while (temp != nullptr) {
        cout << temp->data << " -> ";
        temp = temp->next;
    }
    cout << "NULL\n";
}

int main() {
    // Creating nodes
    Node* head = new Node{10, nullptr};
    head->next = new Node{20, nullptr};
    head->next->next = new Node{30, nullptr};

    // Print the list
    printList(head);

    return 0;
}

    

Learning resource

Readings Linked-List
Videos Linked-List