All algorithms
Data Structures

Linked List

Nodes connected by pointers — traversal and insertion made visible.

TimeO(n) traverseSpaceO(n)CategoryData Structures

A linked list stores each element in its own node, connected to the next by a pointer. Unlike an array it has no contiguous block, so insertion and deletion are O(1) once you hold the node — but random access is O(n).

Pointers are where beginners struggle: what does `head->next` point to, and what happens to the chain when you insert or delete? Following the arrows in memory removes the mystery.

AlgoLens draws each node and the pointer arrows between them, straight from the heap — so `next` is a real arrow you can follow, not an address to imagine.

The code

linked_list.cpp
#include <bits/stdc++.h>
using namespace std;

struct Node {
    int val;
    Node* next;
};

int main() {
    Node* head = nullptr;
    for (int i = 5; i >= 1; i--) {
        head = new Node{i, head};
    }

    int sum = 0;
    for (Node* cur = head; cur != nullptr; cur = cur->next) {
        sum += cur->val;
    }
    cout << sum << '\n';
    return 0;
}
Open this in the visualizer

Now run your own Linked List

AlgoLens traces your code — arrays, graphs, trees and recursion — from a real execution, so you see how it actually behaves, not a canned animation.

Paste your code

Keep going