Click Step and open Memory under the variables: lists and arrays are cells (numbers also as bars), the cells changed by the last step are green, and the index variables (i, j, min) are shown under their cell. In Python, an arrow points to each object: numbers and same point to the same list, and the nodes of the linked list point to each other.
Python (in the browser):
class Node:
def __init__(self, value, next=None):
self.value = value
self.next = next
def bubble(a):
n = len(a)
for i in range(n - 1):
for j in range(n - 1 - i):
if a[j] > a[j + 1]:
a[j], a[j + 1] = a[j + 1], a[j]
numbers = [5, 2, 8, 1, 9, 3]
same = numbers
bubble(numbers)
print(same)
head = Node(1, Node(2, Node(3)))
ages = {"Ana": 16, "Marko": 17}
print(head.next.value, ages["Ana"])
C (on the server), selection sort:
#include <stdio.h>
struct point {
int x, y;
};
int main(void)
{
int a[6] = {5, 2, 8, 1, 9, 3};
int n = 6;
for (int i = 0; i < n - 1; i++) {
int min = i;
for (int j = i + 1; j < n; j++) {
if (a[j] < a[min]) {
min = j;
}
}
int t = a[i];
a[i] = a[min];
a[min] = t;
}
struct point p = {3, 4};
int m[2][3] = {{1, 2, 3}, {4, 5, 6}};
printf("%d %d %d\n", a[0], p.x + p.y, m[1][2]);
return 0;
}
C pointers: p walks through the array (its name moves under the cells), s points to sum, and the nodes of a linked list on the heap point to each other:
#include <stdio.h>
#include <stdlib.h>
struct node {
int value;
struct node *next;
};
int main(void)
{
int a[5] = {4, 8, 15, 16, 23};
int sum = 0;
for (int *p = a; p < a + 5; p++) {
sum += *p;
}
int *s = ∑
struct node *head = NULL;
for (int i = 3; i >= 1; i--) {
struct node *n = malloc(sizeof *n);
n->value = i;
n->next = head;
head = n;
}
printf("%d %d\n", *s, head->next->value);
while (head != NULL) {
struct node *next = head->next;
free(head);
head = next;
}
return 0;
}