LinkedList
LinkedLists are sequences of nodes where each node contains data and connects to the next node. They are perfect for visualizing dynamic data structures and pointer-based algorithms.
Source Code
1linkedlist chain = {2 nodes: [head, node1, node2, tail]3 value: [10, 20, 30, 40]4 color: ["green", "blue", "blue", "red"]5 arrow: ["start", null, null, "end"]6}7
8page9show chainRendered Diagram
Properties
LinkedLists support the following properties:
| Property | Type | Description |
|---|---|---|
nodes | id[] | List of node identifiers |
value | (number | string | null)[] | Values for each node |
color | (color | null)[] | Colors for each node |
arrow | (number | string | null)[] | Arrows or labels for each node |
above | string | text_object (see special features) | Label positioned above the list |
below | string | text_object | Label positioned below the list |
left | string | text_object | Label positioned to the left |
right | string | text_object | Label positioned to the right |
Methods
LinkedLists support these methods for manipulation:
Text Positioning Methods
setText(text, position)- Set or remove text at specific positions ("above","below","left","right")
Node Methods
addNode(name, value?)- Add new node with optional valueinsertNode(index | id, name, value?)- Insert node at specific position or after node ID with optional valueremoveNode(name)- Remove specific nodesetValue(index | id, value)- Set value for node at index or node idsetColor(index | id, color)- Set color for node at index or node idsetArrow(index | id, arrow)- Set arrow for node at index or node id
Value Methods
addValue(value)- Add value to end of listremoveValue(value)- Remove first occurrence of valueremoveAt(index)- Remove node at specific position
Multiple Element Methods
setValues([...])- Set multiple node valuessetColors([...])- Set multiple node colorssetArrows([...])- Set multiple node arrows
Examples
Basic LinkedList Example
LinkedList with Pointers
Source Code
1linkedlist pointers = {2 nodes: [head, curr, next, end]3 value: [1, 2, 3, null]4 color: ["green", "blue", "yellow", "red"]5 arrow: ["head", "current", "next", "null"]6}7
8page9show pointersRendered Diagram
Dynamic LinkedList Operations
Source Code
1linkedlist list = {2 nodes: [n1, n2]3 value: [10, 20]4}5
6page7show list8
9page10list.addNode(n3, 30)11list.setColor(2, "green")12list.setArrow(2, "new")13
14page15// insert by index16list.insertNode(1, n1_5, 15)17list.setColors([null, "blue", null, "green"])18list.setArrows([null, "inserted", null, null])19
20page21// insert after node ID22list.insertNode(n1_5, n1_75, 17.5)23list.setColors([null, "blue", "yellow", null, "green"])24list.setArrows([null, "inserted", "after n1_5", null, null])25
26page27list.removeNode(n2)28list.setValues([10, 15, 30])29list.setColors([null, null, "green"])30list.setArrows([null, null, null])Rendered Diagram
LinkedList Traversal
Source Code
1linkedlist traverse = {2 nodes: [start, mid1, mid2, end]3 value: ["first", "second", "third", "last"]4 color: [null, null, null, null]5}6
7page8show traverse9
10page11traverse.setColor(0, "blue")12traverse.setArrow(0, "visiting")13
14page15traverse.setColor(0, "gray")16traverse.setColor(1, "blue")17traverse.setArrow(0, "visited")18traverse.setArrow(1, "visiting")19
20page21traverse.setColor(1, "gray")22traverse.setColor(2, "blue")23traverse.setArrow(1, "visited")24traverse.setArrow(2, "visiting")Rendered Diagram
Sorted LinkedList Insertion
Source Code
1linkedlist sorted = {2 nodes: [n10, n30, n50]3 value: [10, 30, 50]4 above: "Sorted LinkedList"5 below: "Inserting 25"6}7
8page9show sorted10
11page12// insert after n10 node13sorted.insertNode(n10, n25, 25)14sorted.setColor(1, "red")15sorted.setArrow(1, "inserted")Rendered Diagram
Use Cases
LinkedLists are ideal for:
- Dynamic data structures - Variable-length lists, memory allocation
- Insertion/deletion operations - Efficient mid-list modifications
- Pointer manipulation - Understanding references and links
- Queue implementation - FIFO using linked nodes
- Stack implementation - Alternative to array-based stacks
- Graph representations - Adjacency lists
- Memory management - Free lists, garbage collection
- Algorithm visualization - Merging, splitting, reversing lists
Related
- Methods Reference - Complete list of linkedlist methods
- Array - Alternative linear structure
- Stack - LIFO structure that can use linked nodes
- Graph - Uses similar node-based concepts