Linked lists
insert after a node
kernel
memory
cpu
source
list.c
3
struct
node {
4
long
value;
5
struct
node *next;
6
};
21
n = malloc(
sizeof
*n);
22
n->value = v;
23
n->next = at->next;
24
at->next = n;
25
return
n;
locals
at
0
0
0
0
5
5
d
4
a
1
c
0
3
2
a
0
node 7
n
0
0
0
0
5
5
d
4
a
1
c
0
3
2
e
0
node 9
v
9
the list
what the code means
head
7
12
9
at
n
the end
heap
eight bytes a row, as one number ยท low addresses on top
malloc's own 16 bytes
55d4
a1c0
32a0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
7
value
= 7
at
55d4
a1c0
32a8
0
0
0
0
5
5
d
4
a
1
c
0
3
2
e
0
next
55d4
a1c0
32c0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
c
value
= 12
55d4
a1c0
32c8
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
next
= NULL
55d4
a1c0
32e0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
9
value
= 9
n
55d4
a1c0
32e8
0
0
0
0
5
5
d
4
a
1
c
0
3
2
c
0
next
Inserting moves nothing. One word changes: the next field of at
now holds the address of the new node.