All lessons

Linked Lists

8 min · C examples

Chain nodes with next pointers: traverse, count, and update without shifting a whole array.

C · Linked Lists0/5 cleared

Enemy 1 of 5

This builds a chain of three nodes, each pointing to the next, then walks from the first node to the end while counting them. Press Run to see the count printed.

Why this works

A singly linked list stores values in nodes. Each node holds a value and a next pointer to the following node.

Traverse by walking from head with a while loop: cur = cur.next until cur is None. Inserting at the front is O(1); finding by index is O(n).

You
Syntax Skeleton
Loading editor…
Sign up to fightThis one runs on our servers, so it needs a free account.