<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
a	O
linked	B-Data_Structure
list	I-Data_Structure
is	O
a	O
linear	O
collection	O
of	O
data	B-General_Concept
elements	O
whose	O
order	O
is	O
not	O
given	O
by	O
their	O
physical	O
placement	O
in	O
memory	O
.	O
</s>
<s>
It	O
is	O
a	O
data	B-General_Concept
structure	I-General_Concept
consisting	O
of	O
a	O
collection	O
of	O
nodes	O
which	O
together	O
represent	O
a	O
sequence	O
.	O
</s>
<s>
In	O
its	O
most	O
basic	O
form	O
,	O
each	O
node	B-Data_Structure
contains	O
:	O
data	B-General_Concept
,	O
and	O
a	O
reference	O
(	O
in	O
other	O
words	O
,	O
a	O
link	O
)	O
to	O
the	O
next	O
node	B-Data_Structure
in	O
the	O
sequence	O
.	O
</s>
<s>
This	O
structure	O
allows	O
for	O
efficient	O
insertion	O
or	O
removal	O
of	O
elements	O
from	O
any	O
position	O
in	O
the	O
sequence	O
during	O
iteration	B-Algorithm
.	O
</s>
<s>
A	O
drawback	O
of	O
linked	B-Data_Structure
lists	I-Data_Structure
is	O
that	O
access	O
time	O
is	O
linear	O
(	O
and	O
difficult	O
to	O
pipeline	B-General_Concept
)	O
.	O
</s>
<s>
Faster	O
access	O
,	O
such	O
as	O
random	B-General_Concept
access	I-General_Concept
,	O
is	O
not	O
feasible	O
.	O
</s>
<s>
Arrays	B-Data_Structure
have	O
better	O
cache	B-General_Concept
locality	I-General_Concept
compared	O
to	O
linked	B-Data_Structure
lists	I-Data_Structure
.	O
</s>
<s>
Linked	B-Data_Structure
lists	I-Data_Structure
are	O
among	O
the	O
simplest	O
and	O
most	O
common	O
data	B-General_Concept
structures	I-General_Concept
.	O
</s>
<s>
They	O
can	O
be	O
used	O
to	O
implement	O
several	O
other	O
common	O
abstract	O
data	B-General_Concept
types	O
,	O
including	O
lists	O
,	O
stacks	B-Application
,	O
queues	B-Application
,	O
associative	B-Application
arrays	I-Application
,	O
and	O
S-expressions	B-Protocol
,	O
though	O
it	O
is	O
not	O
uncommon	O
to	O
implement	O
those	O
data	B-General_Concept
structures	I-General_Concept
directly	O
without	O
using	O
a	O
linked	B-Data_Structure
list	I-Data_Structure
as	O
the	O
basis	O
.	O
</s>
<s>
The	O
principal	O
benefit	O
of	O
a	O
linked	B-Data_Structure
list	I-Data_Structure
over	O
a	O
conventional	O
array	B-Data_Structure
is	O
that	O
the	O
list	B-General_Concept
elements	O
can	O
be	O
easily	O
inserted	O
or	O
removed	O
without	O
reallocation	O
or	O
reorganization	O
of	O
the	O
entire	O
structure	O
because	O
the	O
data	B-General_Concept
items	O
do	O
not	O
need	O
to	O
be	O
stored	O
contiguously	O
in	O
memory	O
or	O
on	O
disk	O
,	O
while	O
restructuring	O
an	O
array	B-Data_Structure
at	O
run-time	B-Library
is	O
a	O
much	O
more	O
expensive	O
operation	O
.	O
</s>
<s>
Linked	B-Data_Structure
lists	I-Data_Structure
allow	O
insertion	O
and	O
removal	O
of	O
nodes	O
at	O
any	O
point	O
in	O
the	O
list	B-General_Concept
,	O
and	O
allow	O
doing	O
so	O
with	O
a	O
constant	O
number	O
of	O
operations	O
by	O
keeping	O
the	O
link	O
previous	O
to	O
the	O
link	O
being	O
added	O
or	O
removed	O
in	O
memory	O
during	O
list	B-General_Concept
traversal	O
.	O
</s>
<s>
On	O
the	O
other	O
hand	O
,	O
since	O
simple	O
linked	B-Data_Structure
lists	I-Data_Structure
by	O
themselves	O
do	O
not	O
allow	O
random	B-General_Concept
access	I-General_Concept
to	O
the	O
data	B-General_Concept
or	O
any	O
form	O
of	O
efficient	O
indexing	O
,	O
many	O
basic	O
operations	O
—	O
such	O
as	O
obtaining	O
the	O
last	O
node	B-Data_Structure
of	O
the	O
list	B-General_Concept
,	O
finding	O
a	O
node	B-Data_Structure
that	O
contains	O
a	O
given	O
datum	O
,	O
or	O
locating	O
the	O
place	O
where	O
a	O
new	O
node	B-Data_Structure
should	O
be	O
inserted	O
—	O
may	O
require	O
iterating	O
through	O
most	O
or	O
all	O
of	O
the	O
list	B-General_Concept
elements	O
.	O
</s>
<s>
Linked	B-Data_Structure
lists	I-Data_Structure
were	O
developed	O
in	O
1955	O
–	O
1956	O
,	O
by	O
Allen	O
Newell	O
,	O
Cliff	O
Shaw	O
and	O
Herbert	O
A	O
.	O
Simon	O
at	O
RAND	O
Corporation	O
and	O
Carnegie	O
Mellon	O
University	O
as	O
the	O
primary	O
data	B-General_Concept
structure	I-General_Concept
for	O
their	O
Information	B-Language
Processing	I-Language
Language	I-Language
.	O
</s>
<s>
IPL	B-Language
was	O
used	O
by	O
the	O
authors	O
to	O
develop	O
several	O
early	O
artificial	B-Application
intelligence	I-Application
programs	I-Application
,	O
including	O
the	O
Logic	O
Theory	O
Machine	O
,	O
the	O
General	O
Problem	O
Solver	O
,	O
and	O
a	O
computer	O
chess	O
program	O
.	O
</s>
<s>
The	O
now-classic	O
diagram	O
consisting	O
of	O
blocks	O
representing	O
list	B-General_Concept
nodes	O
with	O
arrows	O
pointing	O
to	O
successive	O
list	B-General_Concept
nodes	O
appears	O
in	O
"	O
Programming	O
the	O
Logic	O
Theory	O
Machine	O
"	O
by	O
Newell	O
and	O
Shaw	O
in	O
Proc	O
.	O
</s>
<s>
Newell	O
and	O
Simon	O
were	O
recognized	O
with	O
the	O
ACM	O
Turing	O
Award	O
in	O
1975	O
for	O
having	O
"	O
made	O
basic	O
contributions	O
to	O
artificial	B-Application
intelligence	I-Application
,	O
the	O
psychology	O
of	O
human	O
cognition	O
,	O
and	O
list	B-Language
processing	I-Language
"	O
.	O
</s>
<s>
The	O
problem	O
of	O
machine	B-Application
translation	I-Application
for	O
natural	O
language	O
processing	O
led	O
Victor	O
Yngve	O
at	O
Massachusetts	O
Institute	O
of	O
Technology	O
(	O
MIT	O
)	O
to	O
use	O
linked	B-Data_Structure
lists	I-Data_Structure
as	O
data	B-General_Concept
structures	I-General_Concept
in	O
his	O
COMIT	O
programming	O
language	O
for	O
computer	O
research	O
in	O
the	O
field	O
of	O
linguistics	O
.	O
</s>
<s>
A	O
report	O
on	O
this	O
language	O
entitled	O
"	O
A	O
programming	O
language	O
for	O
mechanical	B-Application
translation	I-Application
"	O
appeared	O
in	O
Mechanical	B-Application
Translation	I-Application
in	O
1958	O
.	O
</s>
<s>
Another	O
early	O
appearance	O
of	O
linked	B-Data_Structure
lists	I-Data_Structure
was	O
by	O
Hans	O
Peter	O
Luhn	O
who	O
wrote	O
an	O
internal	O
IBM	O
memorandum	O
in	O
January	O
1953	O
that	O
suggested	O
the	O
use	O
of	O
linked	B-Data_Structure
lists	I-Data_Structure
in	O
chained	O
hash	B-Algorithm
tables	I-Algorithm
.	O
</s>
<s>
LISP	B-Language
,	O
standing	O
for	O
list	B-General_Concept
processor	O
,	O
was	O
created	O
by	O
John	O
McCarthy	O
in	O
1958	O
while	O
he	O
was	O
at	O
MIT	O
and	O
in	O
1960	O
he	O
published	O
its	O
design	O
in	O
a	O
paper	O
in	O
the	O
Communications	O
of	O
the	O
ACM	O
,	O
entitled	O
"	O
Recursive	O
Functions	O
of	O
Symbolic	O
Expressions	O
and	O
Their	O
Computation	O
by	O
Machine	O
,	O
Part	O
I	O
"	O
.	O
</s>
<s>
One	O
of	O
LISP	B-Language
's	O
major	O
data	B-General_Concept
structures	I-General_Concept
is	O
the	O
linked	B-Data_Structure
list	I-Data_Structure
.	O
</s>
<s>
By	O
the	O
early	O
1960s	O
,	O
the	O
utility	O
of	O
both	O
linked	B-Data_Structure
lists	I-Data_Structure
and	O
languages	O
which	O
use	O
these	O
structures	O
as	O
their	O
primary	O
data	B-General_Concept
representation	O
was	O
well	O
established	O
.	O
</s>
<s>
Bert	O
Green	O
of	O
the	O
MIT	O
Lincoln	O
Laboratory	O
published	O
a	O
review	O
article	O
entitled	O
"	O
Computer	O
languages	O
for	O
symbol	O
manipulation	O
"	O
in	O
IRE	O
Transactions	O
on	O
Human	O
Factors	O
in	O
Electronics	O
in	O
March	O
1961	O
which	O
summarized	O
the	O
advantages	O
of	O
the	O
linked	B-Data_Structure
list	I-Data_Structure
approach	O
.	O
</s>
<s>
A	O
later	O
review	O
article	O
,	O
"	O
A	O
Comparison	O
of	O
list-processing	O
computer	O
languages	O
"	O
by	O
Bobrow	O
and	O
Raphael	O
,	O
appeared	O
in	O
Communications	O
of	O
the	O
ACM	O
in	O
April	O
1964	O
.	O
</s>
<s>
Several	O
operating	O
systems	O
developed	O
by	O
Technical	O
Systems	O
Consultants	O
(	O
originally	O
of	O
West	O
Lafayette	O
Indiana	O
,	O
and	O
later	O
of	O
Chapel	O
Hill	O
,	O
North	O
Carolina	O
)	O
used	O
singly	O
linked	B-Data_Structure
lists	I-Data_Structure
as	O
file	O
structures	O
.	O
</s>
<s>
Systems	O
using	O
this	O
technique	O
included	O
Flex	O
(	O
for	O
the	O
Motorola	B-Device
6800	I-Device
CPU	O
)	O
,	O
mini-Flex	O
(	O
same	O
CPU	O
)	O
,	O
and	O
Flex9	O
(	O
for	O
the	O
Motorola	O
6809	O
CPU	O
)	O
.	O
</s>
<s>
A	O
variant	O
developed	O
by	O
TSC	O
for	O
and	O
marketed	O
by	O
Smoke	O
Signal	O
Broadcasting	O
in	O
California	O
,	O
used	O
doubly	O
linked	B-Data_Structure
lists	I-Data_Structure
in	O
the	O
same	O
manner	O
.	O
</s>
<s>
The	O
TSS/360	O
operating	O
system	O
,	O
developed	O
by	O
IBM	O
for	O
the	O
System	O
360/370	O
machines	O
,	O
used	O
a	O
double	O
linked	B-Data_Structure
list	I-Data_Structure
for	O
their	O
file	O
system	O
catalog	O
.	O
</s>
<s>
Each	O
record	O
of	O
a	O
linked	B-Data_Structure
list	I-Data_Structure
is	O
often	O
called	O
an	O
'	O
element	O
 '	O
or	O
'	O
node	B-Data_Structure
 '	O
.	O
</s>
<s>
The	O
field	O
of	O
each	O
node	B-Data_Structure
that	O
contains	O
the	O
address	O
of	O
the	O
next	O
node	B-Data_Structure
is	O
usually	O
called	O
the	O
'	O
next	O
link	O
 '	O
or	O
'	O
next	O
pointer	O
 '	O
.	O
</s>
<s>
The	O
remaining	O
fields	O
are	O
known	O
as	O
the	O
'	O
data	B-General_Concept
 '	O
,	O
'	O
information	O
 '	O
,	O
'	O
value	O
 '	O
,	O
'	O
cargo	O
 '	O
,	O
or	O
'	O
payload	O
 '	O
fields	O
.	O
</s>
<s>
The	O
'	O
head	O
 '	O
of	O
a	O
list	B-General_Concept
is	O
its	O
first	O
node	B-Data_Structure
.	O
</s>
<s>
The	O
'	O
tail	O
 '	O
of	O
a	O
list	B-General_Concept
may	O
refer	O
either	O
to	O
the	O
rest	O
of	O
the	O
list	B-General_Concept
after	O
the	O
head	O
,	O
or	O
to	O
the	O
last	O
node	B-Data_Structure
in	O
the	O
list	B-General_Concept
.	O
</s>
<s>
In	O
Lisp	B-Language
and	O
some	O
derived	O
languages	O
,	O
the	O
next	O
node	B-Data_Structure
may	O
be	O
called	O
the	O
'	O
cdr	B-Language
 '	O
(	O
pronounced	O
could-er	O
)	O
of	O
the	O
list	B-General_Concept
,	O
while	O
the	O
payload	O
of	O
the	O
head	O
node	B-Data_Structure
may	O
be	O
called	O
the	O
'	O
car	B-Language
 '	O
.	O
</s>
<s>
Singly	O
linked	B-Data_Structure
lists	I-Data_Structure
contain	O
nodes	O
which	O
have	O
a	O
'	O
value	O
 '	O
field	O
as	O
well	O
as	O
'	O
next	O
 '	O
field	O
,	O
which	O
points	O
to	O
the	O
next	O
node	B-Data_Structure
in	O
line	O
of	O
nodes	O
.	O
</s>
<s>
Operations	O
that	O
can	O
be	O
performed	O
on	O
singly	O
linked	B-Data_Structure
lists	I-Data_Structure
include	O
insertion	O
,	O
deletion	O
and	O
traversal	O
.	O
</s>
<s>
The	O
following	O
code	O
demonstrates	O
how	O
to	O
add	O
a	O
new	O
node	B-Data_Structure
with	O
the	O
"	O
value	O
"	O
to	O
the	O
end	O
of	O
a	O
singly	O
linked	B-Data_Structure
list	I-Data_Structure
:	O
</s>
<s>
In	O
a	O
'	O
doubly	O
linked	B-Data_Structure
list	I-Data_Structure
 '	O
,	O
each	O
node	B-Data_Structure
contains	O
,	O
besides	O
the	O
next-node	O
link	O
,	O
a	O
second	O
link	O
field	O
pointing	O
to	O
the	O
'	O
previous	O
 '	O
node	B-Data_Structure
in	O
the	O
sequence	O
.	O
</s>
<s>
A	O
technique	O
known	O
as	O
XOR-linking	B-Data_Structure
allows	O
a	O
doubly	O
linked	B-Data_Structure
list	I-Data_Structure
to	O
be	O
implemented	O
using	O
a	O
single	O
link	O
field	O
in	O
each	O
node	B-Data_Structure
.	O
</s>
<s>
Many	O
modern	O
operating	O
systems	O
use	O
doubly	O
linked	B-Data_Structure
lists	I-Data_Structure
to	O
maintain	O
references	O
to	O
active	O
processes	O
,	O
threads	O
,	O
and	O
other	O
dynamic	O
objects	O
.	O
</s>
<s>
In	O
a	O
'	O
multiply	O
linked	B-Data_Structure
list	I-Data_Structure
 '	O
,	O
each	O
node	B-Data_Structure
contains	O
two	O
or	O
more	O
link	O
fields	O
,	O
each	O
field	O
being	O
used	O
to	O
connect	O
the	O
same	O
set	O
of	O
data	B-General_Concept
records	O
in	O
a	O
different	O
order	O
of	O
same	O
set	O
(	O
e.g.	O
,	O
by	O
name	O
,	O
by	O
department	O
,	O
by	O
date	O
of	O
birth	O
,	O
etc	O
.	O
)	O
.	O
</s>
<s>
While	O
doubly	O
linked	B-Data_Structure
lists	I-Data_Structure
can	O
be	O
seen	O
as	O
special	O
cases	O
of	O
multiply	O
linked	B-Data_Structure
list	I-Data_Structure
,	O
the	O
fact	O
that	O
the	O
two	O
and	O
more	O
orders	O
are	O
opposite	O
to	O
each	O
other	O
leads	O
to	O
simpler	O
and	O
more	O
efficient	O
algorithms	O
,	O
so	O
they	O
are	O
usually	O
treated	O
as	O
a	O
separate	O
case	O
.	O
</s>
<s>
In	O
the	O
last	O
node	B-Data_Structure
of	O
a	O
list	B-General_Concept
,	O
the	O
link	O
field	O
often	O
contains	O
a	O
null	O
reference	O
,	O
a	O
special	O
value	O
is	O
used	O
to	O
indicate	O
the	O
lack	O
of	O
further	O
nodes	O
.	O
</s>
<s>
A	O
less	O
common	O
convention	O
is	O
to	O
make	O
it	O
point	O
to	O
the	O
first	O
node	B-Data_Structure
of	O
the	O
list	B-General_Concept
;	O
in	O
that	O
case	O
,	O
the	O
list	B-General_Concept
is	O
said	O
to	O
be	O
'	O
circular	O
 '	O
or	O
'	O
circularly	O
linked	O
 '	O
;	O
otherwise	O
,	O
it	O
is	O
said	O
to	O
be	O
'	O
open	O
 '	O
or	O
'	O
linear	O
 '	O
.	O
</s>
<s>
It	O
is	O
a	O
list	B-General_Concept
where	O
the	O
last	O
pointer	O
points	O
to	O
the	O
first	O
node	B-Data_Structure
.	O
</s>
<s>
In	O
the	O
case	O
of	O
a	O
circular	O
doubly	O
linked	B-Data_Structure
list	I-Data_Structure
,	O
the	O
first	O
node	B-Data_Structure
also	O
points	O
to	O
the	O
last	O
node	B-Data_Structure
of	O
the	O
list	B-General_Concept
.	O
</s>
<s>
In	O
some	O
implementations	O
an	O
extra	O
'	O
sentinel	B-Data_Structure
 '	O
or	O
'	O
dummy	O
 '	O
node	B-Data_Structure
may	O
be	O
added	O
before	O
the	O
first	O
data	B-General_Concept
record	O
or	O
after	O
the	O
last	O
one	O
.	O
</s>
<s>
This	O
convention	O
simplifies	O
and	O
accelerates	O
some	O
list-handling	O
algorithms	O
,	O
by	O
ensuring	O
that	O
all	O
links	O
can	O
be	O
safely	O
dereferenced	O
and	O
that	O
every	O
list	B-General_Concept
(	O
even	O
one	O
that	O
contains	O
no	O
data	B-General_Concept
elements	O
)	O
always	O
has	O
a	O
"	O
first	O
"	O
and	O
"	O
last	O
"	O
node	B-Data_Structure
.	O
</s>
<s>
An	O
empty	O
list	B-General_Concept
is	O
a	O
list	B-General_Concept
that	O
contains	O
no	O
data	B-General_Concept
records	O
.	O
</s>
<s>
If	O
sentinel	B-Data_Structure
nodes	I-Data_Structure
are	O
being	O
used	O
,	O
the	O
list	B-General_Concept
is	O
usually	O
said	O
to	O
be	O
empty	O
when	O
it	O
has	O
only	O
sentinel	B-Data_Structure
nodes	I-Data_Structure
.	O
</s>
<s>
If	O
the	O
data	B-General_Concept
records	O
are	O
stored	O
in	O
an	O
array	B-Data_Structure
and	O
referenced	O
by	O
their	O
indices	O
,	O
the	O
link	O
field	O
may	O
be	O
stored	O
in	O
a	O
separate	O
array	B-Data_Structure
with	O
the	O
same	O
indices	O
as	O
the	O
data	B-General_Concept
records	O
.	O
</s>
<s>
Since	O
a	O
reference	O
to	O
the	O
first	O
node	B-Data_Structure
gives	O
access	O
to	O
the	O
whole	O
list	B-General_Concept
,	O
that	O
reference	O
is	O
often	O
called	O
the	O
'	O
address	O
 '	O
,	O
'	O
pointer	O
 '	O
,	O
or	O
'	O
handle	O
 '	O
of	O
the	O
list	B-General_Concept
.	O
</s>
<s>
Algorithms	O
that	O
manipulate	O
linked	B-Data_Structure
lists	I-Data_Structure
usually	O
get	O
such	O
handles	O
to	O
the	O
input	O
lists	O
and	O
return	O
the	O
handles	O
to	O
the	O
resulting	O
lists	O
.	O
</s>
<s>
In	O
fact	O
,	O
in	O
the	O
context	O
of	O
such	O
algorithms	O
,	O
the	O
word	O
"	O
list	B-General_Concept
"	O
often	O
means	O
"	O
list	B-General_Concept
handle	O
"	O
.	O
</s>
<s>
In	O
some	O
situations	O
,	O
however	O
,	O
it	O
may	O
be	O
convenient	O
to	O
refer	O
to	O
a	O
list	B-General_Concept
by	O
a	O
handle	O
that	O
consists	O
of	O
two	O
links	O
,	O
pointing	O
to	O
its	O
first	O
and	O
last	O
nodes	O
.	O
</s>
<s>
The	O
alternatives	O
listed	O
above	O
may	O
be	O
arbitrarily	O
combined	O
in	O
almost	O
every	O
way	O
,	O
so	O
one	O
may	O
have	O
circular	O
doubly	O
linked	B-Data_Structure
lists	I-Data_Structure
without	O
sentinels	O
,	O
circular	O
singly	O
linked	B-Data_Structure
lists	I-Data_Structure
with	O
sentinels	O
,	O
etc	O
.	O
</s>
<s>
A	O
linked	B-Data_Structure
list	I-Data_Structure
data	B-General_Concept
structure	I-General_Concept
might	O
work	O
well	O
in	O
one	O
case	O
,	O
but	O
cause	O
problems	O
in	O
another	O
.	O
</s>
<s>
This	O
is	O
a	O
list	B-General_Concept
of	O
some	O
of	O
the	O
common	O
tradeoffs	O
involving	O
linked	B-Data_Structure
list	I-Data_Structure
structures	O
.	O
</s>
<s>
A	O
dynamic	B-Data_Structure
array	I-Data_Structure
is	O
a	O
data	B-General_Concept
structure	I-General_Concept
that	O
allocates	O
all	O
elements	O
contiguously	O
in	O
memory	O
,	O
and	O
keeps	O
a	O
count	O
of	O
the	O
current	O
number	O
of	O
elements	O
.	O
</s>
<s>
If	O
the	O
space	O
reserved	O
for	O
the	O
dynamic	B-Data_Structure
array	I-Data_Structure
is	O
exceeded	O
,	O
it	O
is	O
reallocated	O
and	O
(	O
possibly	O
)	O
copied	O
,	O
which	O
is	O
an	O
expensive	O
operation	O
.	O
</s>
<s>
Linked	B-Data_Structure
lists	I-Data_Structure
have	O
several	O
advantages	O
over	O
dynamic	B-Data_Structure
arrays	I-Data_Structure
.	O
</s>
<s>
Insertion	O
or	O
deletion	O
of	O
an	O
element	O
at	O
a	O
specific	O
point	O
of	O
a	O
list	B-General_Concept
,	O
assuming	O
that	O
we	O
have	O
indexed	O
a	O
pointer	O
to	O
the	O
node	B-Data_Structure
(	O
before	O
the	O
one	O
to	O
be	O
removed	O
,	O
or	O
before	O
the	O
insertion	O
point	O
)	O
already	O
,	O
is	O
a	O
constant-time	O
operation	O
(	O
otherwise	O
without	O
this	O
reference	O
it	O
is	O
O(n )	O
)	O
,	O
whereas	O
insertion	O
in	O
a	O
dynamic	B-Data_Structure
array	I-Data_Structure
at	O
random	O
locations	O
will	O
require	O
moving	O
half	O
of	O
the	O
elements	O
on	O
average	O
,	O
and	O
all	O
the	O
elements	O
in	O
the	O
worst	O
case	O
.	O
</s>
<s>
While	O
one	O
can	O
"	O
delete	O
"	O
an	O
element	O
from	O
an	O
array	B-Data_Structure
in	O
constant	O
time	O
by	O
somehow	O
marking	O
its	O
slot	O
as	O
"	O
vacant	O
"	O
,	O
this	O
causes	O
fragmentation	B-Architecture
that	O
impedes	O
the	O
performance	O
of	O
iteration	B-Algorithm
.	O
</s>
<s>
Moreover	O
,	O
arbitrarily	O
many	O
elements	O
may	O
be	O
inserted	O
into	O
a	O
linked	B-Data_Structure
list	I-Data_Structure
,	O
limited	O
only	O
by	O
the	O
total	O
memory	O
available	O
;	O
while	O
a	O
dynamic	B-Data_Structure
array	I-Data_Structure
will	O
eventually	O
fill	O
up	O
its	O
underlying	O
array	B-Data_Structure
data	I-Data_Structure
structure	I-Data_Structure
and	O
will	O
have	O
to	O
reallocate	O
—	O
an	O
expensive	O
operation	O
,	O
one	O
that	O
may	O
not	O
even	O
be	O
possible	O
if	O
memory	O
is	O
fragmented	O
,	O
although	O
the	O
cost	O
of	O
reallocation	O
can	O
be	O
averaged	O
over	O
insertions	O
,	O
and	O
the	O
cost	O
of	O
an	O
insertion	O
due	O
to	O
reallocation	O
would	O
still	O
be	O
amortized	B-General_Concept
O(1 )	O
.	O
</s>
<s>
This	O
helps	O
with	O
appending	O
elements	O
at	O
the	O
array	B-Data_Structure
's	O
end	O
,	O
but	O
inserting	O
into	O
(	O
or	O
removing	O
from	O
)	O
middle	O
positions	O
still	O
carries	O
prohibitive	O
costs	O
due	O
to	O
data	B-General_Concept
moving	O
to	O
maintain	O
contiguity	O
.	O
</s>
<s>
An	O
array	B-Data_Structure
from	O
which	O
many	O
elements	O
are	O
removed	O
may	O
also	O
have	O
to	O
be	O
resized	O
in	O
order	O
to	O
avoid	O
wasting	O
too	O
much	O
space	O
.	O
</s>
<s>
On	O
the	O
other	O
hand	O
,	O
dynamic	B-Data_Structure
arrays	I-Data_Structure
(	O
as	O
well	O
as	O
fixed-size	O
array	B-Data_Structure
data	I-Data_Structure
structures	I-Data_Structure
)	O
allow	O
constant-time	O
random	B-General_Concept
access	I-General_Concept
,	O
while	O
linked	B-Data_Structure
lists	I-Data_Structure
allow	O
only	O
sequential	B-General_Concept
access	I-General_Concept
to	O
elements	O
.	O
</s>
<s>
Singly	O
linked	B-Data_Structure
lists	I-Data_Structure
,	O
in	O
fact	O
,	O
can	O
be	O
easily	O
traversed	O
in	O
only	O
one	O
direction	O
.	O
</s>
<s>
This	O
makes	O
linked	B-Data_Structure
lists	I-Data_Structure
unsuitable	O
for	O
applications	O
where	O
it	O
's	O
useful	O
to	O
look	O
up	O
an	O
element	O
by	O
its	O
index	B-Data_Structure
quickly	O
,	O
such	O
as	O
heapsort	B-Application
.	O
</s>
<s>
Sequential	B-General_Concept
access	I-General_Concept
on	O
arrays	B-Data_Structure
and	O
dynamic	B-Data_Structure
arrays	I-Data_Structure
is	O
also	O
faster	O
than	O
on	O
linked	B-Data_Structure
lists	I-Data_Structure
on	O
many	O
machines	O
,	O
because	O
they	O
have	O
optimal	O
locality	B-General_Concept
of	I-General_Concept
reference	I-General_Concept
and	O
thus	O
make	O
good	O
use	O
of	O
data	B-General_Concept
caching	O
.	O
</s>
<s>
Another	O
disadvantage	O
of	O
linked	B-Data_Structure
lists	I-Data_Structure
is	O
the	O
extra	O
storage	O
needed	O
for	O
references	O
,	O
which	O
often	O
makes	O
them	O
impractical	O
for	O
lists	O
of	O
small	O
data	B-General_Concept
items	O
such	O
as	O
characters	O
or	O
boolean	O
values	O
,	O
because	O
the	O
storage	O
overhead	O
for	O
the	O
links	O
may	O
exceed	O
by	O
a	O
factor	O
of	O
two	O
or	O
more	O
the	O
size	O
of	O
the	O
data	B-General_Concept
.	O
</s>
<s>
In	O
contrast	O
,	O
a	O
dynamic	B-Data_Structure
array	I-Data_Structure
requires	O
only	O
the	O
space	O
for	O
the	O
data	B-General_Concept
itself	O
(	O
and	O
a	O
very	O
small	O
amount	O
of	O
control	O
data	B-General_Concept
)	O
.	O
</s>
<s>
It	O
can	O
also	O
be	O
slow	O
,	O
and	O
with	O
a	O
naïve	O
allocator	O
,	O
wasteful	O
,	O
to	O
allocate	O
memory	O
separately	O
for	O
each	O
new	O
element	O
,	O
a	O
problem	O
generally	O
solved	O
using	O
memory	B-General_Concept
pools	I-General_Concept
.	O
</s>
<s>
Unrolled	B-Data_Structure
linked	I-Data_Structure
lists	I-Data_Structure
store	O
several	O
elements	O
in	O
each	O
list	B-General_Concept
node	B-Data_Structure
,	O
increasing	O
cache	B-General_Concept
performance	O
while	O
decreasing	O
memory	O
overhead	O
for	O
references	O
.	O
</s>
<s>
CDR	B-Language
coding	I-Language
does	O
both	O
these	O
as	O
well	O
,	O
by	O
replacing	O
references	O
with	O
the	O
actual	O
data	B-General_Concept
referenced	O
,	O
which	O
extends	O
off	O
the	O
end	O
of	O
the	O
referencing	O
record	O
.	O
</s>
<s>
A	O
good	O
example	O
that	O
highlights	O
the	O
pros	O
and	O
cons	B-Protocol
of	O
using	O
dynamic	B-Data_Structure
arrays	I-Data_Structure
vs.	O
linked	B-Data_Structure
lists	I-Data_Structure
is	O
by	O
implementing	O
a	O
program	O
that	O
resolves	O
the	O
Josephus	O
problem	O
.	O
</s>
<s>
This	O
shows	O
the	O
strengths	O
and	O
weaknesses	O
of	O
a	O
linked	B-Data_Structure
list	I-Data_Structure
vs.	O
a	O
dynamic	B-Data_Structure
array	I-Data_Structure
,	O
because	O
if	O
the	O
people	O
are	O
viewed	O
as	O
connected	O
nodes	O
in	O
a	O
circular	O
linked	B-Data_Structure
list	I-Data_Structure
,	O
then	O
it	O
shows	O
how	O
easily	O
the	O
linked	B-Data_Structure
list	I-Data_Structure
is	O
able	O
to	O
delete	O
nodes	O
(	O
as	O
it	O
only	O
has	O
to	O
rearrange	O
the	O
links	O
to	O
the	O
different	O
nodes	O
)	O
.	O
</s>
<s>
However	O
,	O
the	O
linked	B-Data_Structure
list	I-Data_Structure
will	O
be	O
poor	O
at	O
finding	O
the	O
next	O
person	O
to	O
remove	O
and	O
will	O
need	O
to	O
search	O
through	O
the	O
list	B-General_Concept
until	O
it	O
finds	O
that	O
person	O
.	O
</s>
<s>
A	O
dynamic	B-Data_Structure
array	I-Data_Structure
,	O
on	O
the	O
other	O
hand	O
,	O
will	O
be	O
poor	O
at	O
deleting	O
nodes	O
(	O
or	O
elements	O
)	O
as	O
it	O
cannot	O
remove	O
one	O
node	B-Data_Structure
without	O
individually	O
shifting	O
all	O
the	O
elements	O
up	O
the	O
list	B-General_Concept
by	O
one	O
.	O
</s>
<s>
However	O
,	O
it	O
is	O
exceptionally	O
easy	O
to	O
find	O
the	O
nth	O
person	O
in	O
the	O
circle	O
by	O
directly	O
referencing	O
them	O
by	O
their	O
position	O
in	O
the	O
array	B-Data_Structure
.	O
</s>
<s>
The	O
list	B-Operating_System
ranking	I-Operating_System
problem	O
concerns	O
the	O
efficient	O
conversion	O
of	O
a	O
linked	B-Data_Structure
list	I-Data_Structure
representation	O
into	O
an	O
array	B-Data_Structure
.	O
</s>
<s>
Although	O
trivial	O
for	O
a	O
conventional	O
computer	O
,	O
solving	O
this	O
problem	O
by	O
a	O
parallel	B-Operating_System
algorithm	I-Operating_System
is	O
complicated	O
and	O
has	O
been	O
the	O
subject	O
of	O
much	O
research	O
.	O
</s>
<s>
A	O
balanced	B-Data_Structure
tree	I-Data_Structure
has	O
similar	O
memory	O
access	O
patterns	O
and	O
space	O
overhead	O
to	O
a	O
linked	B-Data_Structure
list	I-Data_Structure
while	O
permitting	O
much	O
more	O
efficient	O
indexing	O
,	O
taking	O
O(log n )	O
time	O
instead	O
of	O
O(n )	O
for	O
a	O
random	B-General_Concept
access	I-General_Concept
.	O
</s>
<s>
A	O
singly	O
linked	O
linear	O
list	B-General_Concept
is	O
a	O
recursive	O
data	B-General_Concept
structure	I-General_Concept
,	O
because	O
it	O
contains	O
a	O
pointer	O
to	O
a	O
smaller	O
object	O
of	O
the	O
same	O
type	O
.	O
</s>
<s>
For	O
that	O
reason	O
,	O
many	O
operations	O
on	O
singly	O
linked	O
linear	O
lists	O
(	O
such	O
as	O
merging	B-Algorithm
two	O
lists	O
,	O
or	O
enumerating	O
the	O
elements	O
in	O
reverse	O
order	O
)	O
often	O
have	O
very	O
simple	O
recursive	O
algorithms	O
,	O
much	O
simpler	O
than	O
any	O
solution	O
using	O
iterative	B-Algorithm
commands	O
.	O
</s>
<s>
While	O
those	O
recursive	O
solutions	O
can	O
be	O
adapted	O
for	O
doubly	O
linked	O
and	O
circularly	O
linked	B-Data_Structure
lists	I-Data_Structure
,	O
the	O
procedures	O
generally	O
need	O
extra	O
arguments	O
and	O
more	O
complicated	O
base	O
cases	O
.	O
</s>
<s>
Linear	O
singly	O
linked	B-Data_Structure
lists	I-Data_Structure
also	O
allow	O
tail-sharing	B-Data_Structure
,	O
the	O
use	O
of	O
a	O
common	O
final	O
portion	O
of	O
sub-list	O
as	O
the	O
terminal	O
portion	O
of	O
two	O
different	O
lists	O
.	O
</s>
<s>
In	O
particular	O
,	O
if	O
a	O
new	O
node	B-Data_Structure
is	O
added	O
at	O
the	O
beginning	O
of	O
a	O
list	B-General_Concept
,	O
the	O
former	O
list	B-General_Concept
remains	O
available	O
as	O
the	O
tail	O
of	O
the	O
new	O
one	O
—	O
a	O
simple	O
example	O
of	O
a	O
persistent	B-Application
data	I-Application
structure	I-Application
.	O
</s>
<s>
Again	O
,	O
this	O
is	O
not	O
true	O
with	O
the	O
other	O
variants	O
:	O
a	O
node	B-Data_Structure
may	O
never	O
belong	O
to	O
two	O
different	O
circular	O
or	O
doubly	O
linked	B-Data_Structure
lists	I-Data_Structure
.	O
</s>
<s>
The	O
same	O
end-sentinel	O
node	O
may	O
be	O
used	O
for	O
every	O
such	O
list	B-General_Concept
.	O
</s>
<s>
In	O
Lisp	B-Language
,	O
for	O
example	O
,	O
every	O
proper	O
list	B-General_Concept
ends	O
with	O
a	O
link	O
to	O
a	O
special	O
node	B-Data_Structure
,	O
denoted	O
by	O
nil	O
or	O
(	O
)	O
,	O
whose	O
CAR	B-Language
and	I-Language
CDR	I-Language
links	O
point	O
to	O
itself	O
.	O
</s>
<s>
Thus	O
a	O
Lisp	B-Language
procedure	O
can	O
safely	O
take	O
the	O
CAR	B-Language
or	O
CDR	B-Language
of	O
any	O
list	B-General_Concept
.	O
</s>
<s>
A	O
circular	O
list	B-General_Concept
,	O
in	O
particular	O
,	O
can	O
usually	O
be	O
emulated	O
by	O
a	O
linear	O
list	B-General_Concept
together	O
with	O
two	O
variables	O
that	O
point	O
to	O
the	O
first	O
and	O
last	O
nodes	O
,	O
at	O
no	O
extra	O
cost	O
.	O
</s>
<s>
Double-linked	O
lists	O
require	O
more	O
space	O
per	O
node	B-Data_Structure
(	O
unless	O
one	O
uses	O
XOR-linking	B-Data_Structure
)	O
,	O
and	O
their	O
elementary	O
operations	O
are	O
more	O
expensive	O
;	O
but	O
they	O
are	O
often	O
easier	O
to	O
manipulate	O
because	O
they	O
allow	O
fast	O
and	O
easy	O
sequential	B-General_Concept
access	I-General_Concept
to	O
the	O
list	B-General_Concept
in	O
both	O
directions	O
.	O
</s>
<s>
In	O
a	O
doubly	O
linked	B-Data_Structure
list	I-Data_Structure
,	O
one	O
can	O
insert	O
or	O
delete	O
a	O
node	B-Data_Structure
in	O
a	O
constant	O
number	O
of	O
operations	O
given	O
only	O
that	O
node	B-Data_Structure
's	O
address	O
.	O
</s>
<s>
To	O
do	O
the	O
same	O
in	O
a	O
singly	O
linked	B-Data_Structure
list	I-Data_Structure
,	O
one	O
must	O
have	O
the	O
address	O
of	O
the	O
pointer	O
to	O
that	O
node	B-Data_Structure
,	O
which	O
is	O
either	O
the	O
handle	O
for	O
the	O
whole	O
list	B-General_Concept
(	O
in	O
case	O
of	O
the	O
first	O
node	B-Data_Structure
)	O
or	O
the	O
link	O
field	O
in	O
the	O
previous	O
node	B-Data_Structure
.	O
</s>
<s>
On	O
the	O
other	O
hand	O
,	O
doubly	O
linked	B-Data_Structure
lists	I-Data_Structure
do	O
not	O
allow	O
tail-sharing	B-Data_Structure
and	O
cannot	O
be	O
used	O
as	O
persistent	B-Application
data	I-Application
structures	I-Application
.	O
</s>
<s>
A	O
circularly	O
linked	B-Data_Structure
list	I-Data_Structure
may	O
be	O
a	O
natural	O
option	O
to	O
represent	O
arrays	B-Data_Structure
that	O
are	O
naturally	O
circular	O
,	O
e.g.	O
</s>
<s>
the	O
corners	O
of	O
a	O
polygon	B-General_Concept
,	O
a	O
pool	O
of	O
buffers	B-General_Concept
that	O
are	O
used	O
and	O
released	O
in	O
FIFO	B-Operating_System
(	O
"	O
first	B-Operating_System
in	I-Operating_System
,	I-Operating_System
first	I-Operating_System
out	I-Operating_System
"	O
)	O
order	O
,	O
or	O
a	O
set	O
of	O
processes	O
that	O
should	O
be	O
time-shared	B-General_Concept
in	O
round-robin	B-Algorithm
order	I-Algorithm
.	O
</s>
<s>
In	O
these	O
applications	O
,	O
a	O
pointer	O
to	O
any	O
node	B-Data_Structure
serves	O
as	O
a	O
handle	O
to	O
the	O
whole	O
list	B-General_Concept
.	O
</s>
<s>
With	O
a	O
circular	O
list	B-General_Concept
,	O
a	O
pointer	O
to	O
the	O
last	O
node	B-Data_Structure
gives	O
easy	O
access	O
also	O
to	O
the	O
first	O
node	B-Data_Structure
,	O
by	O
following	O
one	O
link	O
.	O
</s>
<s>
Thus	O
,	O
in	O
applications	O
that	O
require	O
access	O
to	O
both	O
ends	O
of	O
the	O
list	B-General_Concept
(	O
e.g.	O
,	O
in	O
the	O
implementation	O
of	O
a	O
queue	B-Application
)	O
,	O
a	O
circular	O
structure	O
allows	O
one	O
to	O
handle	O
the	O
structure	O
by	O
a	O
single	O
pointer	O
,	O
instead	O
of	O
two	O
.	O
</s>
<s>
A	O
circular	O
list	B-General_Concept
can	O
be	O
split	O
into	O
two	O
circular	O
lists	O
,	O
in	O
constant	O
time	O
,	O
by	O
giving	O
the	O
addresses	O
of	O
the	O
last	O
node	B-Data_Structure
of	O
each	O
piece	O
.	O
</s>
<s>
Applying	O
the	O
same	O
operation	O
to	O
any	O
two	O
nodes	O
in	O
two	O
distinct	O
lists	O
joins	O
the	O
two	O
list	B-General_Concept
into	O
one	O
.	O
</s>
<s>
This	O
property	O
greatly	O
simplifies	O
some	O
algorithms	O
and	O
data	B-General_Concept
structures	I-General_Concept
,	O
such	O
as	O
the	O
quad-edge	B-Algorithm
and	O
face-edge	O
.	O
</s>
<s>
The	O
simplest	O
representation	O
for	O
an	O
empty	O
circular	O
list	B-General_Concept
(	O
when	O
such	O
a	O
thing	O
makes	O
sense	O
)	O
is	O
a	O
null	O
pointer	O
,	O
indicating	O
that	O
the	O
list	B-General_Concept
has	O
no	O
nodes	O
.	O
</s>
<s>
By	O
contrast	O
,	O
the	O
use	O
of	O
null	O
to	O
denote	O
an	O
empty	O
linear	O
list	B-General_Concept
is	O
more	O
natural	O
and	O
often	O
creates	O
fewer	O
special	O
cases	O
.	O
</s>
<s>
For	O
some	O
applications	O
,	O
it	O
can	O
be	O
useful	O
to	O
use	O
singly	O
linked	B-Data_Structure
lists	I-Data_Structure
that	O
can	O
vary	O
between	O
being	O
circular	O
and	O
being	O
linear	O
,	O
or	O
even	O
circular	O
with	O
a	O
linear	O
initial	O
segment	O
.	O
</s>
<s>
One	O
well-known	B-Algorithm
method	I-Algorithm
is	O
to	O
have	O
a	O
second	O
pointer	O
walking	O
the	O
list	B-General_Concept
at	O
half	O
or	O
double	O
the	O
speed	O
,	O
and	O
if	O
both	O
pointers	O
meet	O
at	O
the	O
same	O
node	B-Data_Structure
,	O
you	O
know	O
you	O
found	O
a	O
cycle	O
.	O
</s>
<s>
Sentinel	B-Data_Structure
node	I-Data_Structure
may	O
simplify	O
certain	O
list	B-General_Concept
operations	O
,	O
by	O
ensuring	O
that	O
the	O
next	O
or	O
previous	O
nodes	O
exist	O
for	O
every	O
element	O
,	O
and	O
that	O
even	O
empty	O
lists	O
have	O
at	O
least	O
one	O
node	B-Data_Structure
.	O
</s>
<s>
One	O
may	O
also	O
use	O
a	O
sentinel	B-Data_Structure
node	I-Data_Structure
at	O
the	O
end	O
of	O
the	O
list	B-General_Concept
,	O
with	O
an	O
appropriate	O
data	B-General_Concept
field	O
,	O
to	O
eliminate	O
some	O
end-of-list	O
tests	O
.	O
</s>
<s>
For	O
example	O
,	O
when	O
scanning	O
the	O
list	B-General_Concept
looking	O
for	O
a	O
node	B-Data_Structure
with	O
a	O
given	O
value	O
x	O
,	O
setting	O
the	O
sentinel	B-Data_Structure
's	O
data	B-General_Concept
field	O
to	O
x	O
makes	O
it	O
unnecessary	O
to	O
test	O
for	O
end-of-list	O
inside	O
the	O
loop	O
.	O
</s>
<s>
Another	O
example	O
is	O
the	O
merging	B-Algorithm
two	O
sorted	O
lists	O
:	O
if	O
their	O
sentinels	O
have	O
data	B-General_Concept
fields	O
set	O
to	O
+∞	O
,	O
the	O
choice	O
of	O
the	O
next	O
output	O
node	B-Data_Structure
does	O
not	O
need	O
special	O
handling	O
for	O
empty	O
lists	O
.	O
</s>
<s>
However	O
,	O
sentinel	B-Data_Structure
nodes	I-Data_Structure
use	O
up	O
extra	O
space	O
(	O
especially	O
in	O
applications	O
that	O
use	O
many	O
short	O
lists	O
)	O
,	O
and	O
they	O
may	O
complicate	O
other	O
operations	O
(	O
such	O
as	O
the	O
creation	O
of	O
a	O
new	O
empty	O
list	B-General_Concept
)	O
.	O
</s>
<s>
However	O
,	O
if	O
the	O
circular	O
list	B-General_Concept
is	O
used	O
merely	O
to	O
simulate	O
a	O
linear	O
list	B-General_Concept
,	O
one	O
may	O
avoid	O
some	O
of	O
this	O
complexity	O
by	O
adding	O
a	O
single	O
sentinel	B-Data_Structure
node	I-Data_Structure
to	O
every	O
list	B-General_Concept
,	O
between	O
the	O
last	O
and	O
the	O
first	O
data	B-General_Concept
nodes	O
.	O
</s>
<s>
With	O
this	O
convention	O
,	O
an	O
empty	O
list	B-General_Concept
consists	O
of	O
the	O
sentinel	B-Data_Structure
node	I-Data_Structure
alone	O
,	O
pointing	O
to	O
itself	O
via	O
the	O
next-node	O
link	O
.	O
</s>
<s>
The	O
list	B-General_Concept
handle	O
should	O
then	O
be	O
a	O
pointer	O
to	O
the	O
last	O
data	B-General_Concept
node	B-Data_Structure
,	O
before	O
the	O
sentinel	B-Data_Structure
,	O
if	O
the	O
list	B-General_Concept
is	O
not	O
empty	O
;	O
or	O
to	O
the	O
sentinel	B-Data_Structure
itself	O
,	O
if	O
the	O
list	B-General_Concept
is	O
empty	O
.	O
</s>
<s>
The	O
same	O
trick	O
can	O
be	O
used	O
to	O
simplify	O
the	O
handling	O
of	O
a	O
doubly	O
linked	O
linear	O
list	B-General_Concept
,	O
by	O
turning	O
it	O
into	O
a	O
circular	O
doubly	O
linked	B-Data_Structure
list	I-Data_Structure
with	O
a	O
single	O
sentinel	B-Data_Structure
node	I-Data_Structure
.	O
</s>
<s>
However	O
,	O
in	O
this	O
case	O
,	O
the	O
handle	O
should	O
be	O
a	O
single	O
pointer	O
to	O
the	O
dummy	O
node	B-Data_Structure
itself	O
.	O
</s>
<s>
When	O
manipulating	O
linked	B-Data_Structure
lists	I-Data_Structure
in-place	O
,	O
care	O
must	O
be	O
taken	O
to	O
not	O
use	O
values	O
that	O
you	O
have	O
invalidated	O
in	O
previous	O
assignments	O
.	O
</s>
<s>
This	O
makes	O
algorithms	O
for	O
inserting	O
or	O
deleting	O
linked	B-Data_Structure
list	I-Data_Structure
nodes	O
somewhat	O
subtle	O
.	O
</s>
<s>
This	O
section	O
gives	O
pseudocode	B-Language
for	O
adding	O
or	O
removing	O
nodes	O
from	O
singly	O
,	O
doubly	O
,	O
and	O
circularly	O
linked	B-Data_Structure
lists	I-Data_Structure
in-place	O
.	O
</s>
<s>
Throughout	O
we	O
will	O
use	O
null	O
to	O
refer	O
to	O
an	O
end-of-list	O
marker	O
or	O
sentinel	B-Data_Structure
,	O
which	O
may	O
be	O
implemented	O
in	O
a	O
number	O
of	O
ways	O
.	O
</s>
<s>
Our	O
node	B-Data_Structure
data	B-General_Concept
structure	I-General_Concept
will	O
have	O
two	O
fields	O
.	O
</s>
<s>
We	O
also	O
keep	O
a	O
variable	O
firstNode	O
which	O
always	O
points	O
to	O
the	O
first	O
node	B-Data_Structure
in	O
the	O
list	B-General_Concept
,	O
or	O
is	O
null	O
for	O
an	O
empty	O
list	B-General_Concept
.	O
</s>
<s>
Traversal	O
of	O
a	O
singly	O
linked	B-Data_Structure
list	I-Data_Structure
is	O
simple	O
,	O
beginning	O
at	O
the	O
first	O
node	B-Data_Structure
and	O
following	O
each	O
next	O
link	O
until	O
we	O
come	O
to	O
the	O
end	O
:	O
</s>
<s>
The	O
following	O
code	O
inserts	O
a	O
node	B-Data_Structure
after	O
an	O
existing	O
node	B-Data_Structure
in	O
a	O
singly	O
linked	B-Data_Structure
list	I-Data_Structure
.	O
</s>
<s>
Inserting	O
a	O
node	B-Data_Structure
before	O
an	O
existing	O
one	O
cannot	O
be	O
done	O
directly	O
;	O
instead	O
,	O
one	O
must	O
keep	O
track	O
of	O
the	O
previous	O
node	B-Data_Structure
and	O
insert	O
a	O
node	B-Data_Structure
after	O
it	O
.	O
</s>
<s>
Inserting	O
at	O
the	O
beginning	O
of	O
the	O
list	B-General_Concept
requires	O
a	O
separate	O
function	O
.	O
</s>
<s>
Similarly	O
,	O
we	O
have	O
functions	O
for	O
removing	O
the	O
node	B-Data_Structure
after	O
a	O
given	O
node	B-Data_Structure
,	O
and	O
for	O
removing	O
a	O
node	B-Data_Structure
from	O
the	O
beginning	O
of	O
the	O
list	B-General_Concept
.	O
</s>
<s>
To	O
find	O
and	O
remove	O
a	O
particular	O
node	B-Data_Structure
,	O
one	O
must	O
again	O
keep	O
track	O
of	O
the	O
previous	O
element	O
.	O
</s>
<s>
Notice	O
that	O
removeBeginning( )	O
sets	O
list.firstNode	O
to	O
null	O
when	O
removing	O
the	O
last	O
node	B-Data_Structure
in	O
the	O
list	B-General_Concept
.	O
</s>
<s>
Since	O
we	O
ca	O
n't	O
iterate	B-Algorithm
backwards	O
,	O
efficient	O
insertBefore	O
or	O
removeBefore	O
operations	O
are	O
not	O
possible	O
.	O
</s>
<s>
Inserting	O
to	O
a	O
list	B-General_Concept
before	O
a	O
specific	O
node	B-Data_Structure
requires	O
traversing	O
the	O
list	B-General_Concept
,	O
which	O
would	O
have	O
a	O
worst	O
case	O
running	O
time	O
of	O
O(n )	O
.	O
</s>
<s>
Appending	O
one	O
linked	B-Data_Structure
list	I-Data_Structure
to	O
another	O
can	O
be	O
inefficient	O
unless	O
a	O
reference	O
to	O
the	O
tail	O
is	O
kept	O
as	O
part	O
of	O
the	O
List	B-General_Concept
structure	O
,	O
because	O
we	O
must	O
traverse	O
the	O
entire	O
first	O
list	B-General_Concept
in	O
order	O
to	O
find	O
the	O
tail	O
,	O
and	O
then	O
append	B-Application
the	O
second	O
list	B-General_Concept
to	O
this	O
.	O
</s>
<s>
Thus	O
,	O
if	O
two	O
linearly	O
linked	B-Data_Structure
lists	I-Data_Structure
are	O
each	O
of	O
length	O
,	O
list	B-General_Concept
appending	O
has	O
asymptotic	O
time	O
complexity	O
of	O
.	O
</s>
<s>
In	O
the	O
Lisp	B-Language
family	O
of	O
languages	O
,	O
list	B-General_Concept
appending	O
is	O
provided	O
by	O
the	O
append	B-Application
procedure	O
.	O
</s>
<s>
Many	O
of	O
the	O
special	O
cases	O
of	O
linked	B-Data_Structure
list	I-Data_Structure
operations	O
can	O
be	O
eliminated	O
by	O
including	O
a	O
dummy	O
element	O
at	O
the	O
front	O
of	O
the	O
list	B-General_Concept
.	O
</s>
<s>
This	O
ensures	O
that	O
there	O
are	O
no	O
special	O
cases	O
for	O
the	O
beginning	O
of	O
the	O
list	B-General_Concept
and	O
renders	O
both	O
insertBeginning( )	O
and	O
removeBeginning( )	O
unnecessary	O
.	O
</s>
<s>
In	O
this	O
case	O
,	O
the	O
first	O
useful	O
data	B-General_Concept
in	O
the	O
list	B-General_Concept
will	O
be	O
found	O
at	O
list.firstNode.next	O
.	O
</s>
<s>
In	O
a	O
circularly	O
linked	B-Data_Structure
list	I-Data_Structure
,	O
all	O
nodes	O
are	O
linked	O
in	O
a	O
continuous	O
circle	O
,	O
without	O
using	O
null	O
.	O
</s>
<s>
For	O
lists	O
with	O
a	O
front	O
and	O
a	O
back	O
(	O
such	O
as	O
a	O
queue	B-Application
)	O
,	O
one	O
stores	O
a	O
reference	O
to	O
the	O
last	O
node	B-Data_Structure
in	O
the	O
list	B-General_Concept
.	O
</s>
<s>
The	O
next	O
node	B-Data_Structure
after	O
the	O
last	O
node	B-Data_Structure
is	O
the	O
first	O
node	B-Data_Structure
.	O
</s>
<s>
Elements	O
can	O
be	O
added	O
to	O
the	O
back	O
of	O
the	O
list	B-General_Concept
and	O
removed	O
from	O
the	O
front	O
in	O
constant	O
time	O
.	O
</s>
<s>
Circularly	O
linked	B-Data_Structure
lists	I-Data_Structure
can	O
be	O
either	O
singly	O
or	O
doubly	O
linked	O
.	O
</s>
<s>
Both	O
types	O
of	O
circularly	O
linked	B-Data_Structure
lists	I-Data_Structure
benefit	O
from	O
the	O
ability	O
to	O
traverse	O
the	O
full	O
list	B-General_Concept
beginning	O
at	O
any	O
given	O
node	B-Data_Structure
.	O
</s>
<s>
This	O
often	O
allows	O
us	O
to	O
avoid	O
storing	O
firstNode	O
and	O
lastNode	O
,	O
although	O
if	O
the	O
list	B-General_Concept
may	O
be	O
empty	O
we	O
need	O
a	O
special	O
representation	O
for	O
the	O
empty	O
list	B-General_Concept
,	O
such	O
as	O
a	O
lastNode	O
variable	O
which	O
points	O
to	O
some	O
node	B-Data_Structure
in	O
the	O
list	B-General_Concept
or	O
is	O
null	O
if	O
it	O
's	O
empty	O
;	O
we	O
use	O
such	O
a	O
lastNode	O
here	O
.	O
</s>
<s>
This	O
representation	O
significantly	O
simplifies	O
adding	O
and	O
removing	O
nodes	O
with	O
a	O
non-empty	O
list	B-General_Concept
,	O
but	O
empty	O
lists	O
are	O
then	O
a	O
special	O
case	O
.	O
</s>
<s>
Assuming	O
that	O
someNode	O
is	O
some	O
node	B-Data_Structure
in	O
a	O
non-empty	O
circular	O
singly	O
linked	B-Data_Structure
list	I-Data_Structure
,	O
this	O
code	O
iterates	B-Algorithm
through	O
that	O
list	B-General_Concept
starting	O
with	O
someNode	O
:	O
</s>
<s>
Notice	O
that	O
the	O
test	O
"	O
while	O
node	B-Data_Structure
≠	O
someNode	O
"	O
must	O
be	O
at	O
the	O
end	O
of	O
the	O
loop	O
.	O
</s>
<s>
If	O
the	O
test	O
was	O
moved	O
to	O
the	O
beginning	O
of	O
the	O
loop	O
,	O
the	O
procedure	O
would	O
fail	O
whenever	O
the	O
list	B-General_Concept
had	O
only	O
one	O
node	B-Data_Structure
.	O
</s>
<s>
This	O
function	O
inserts	O
a	O
node	B-Data_Structure
"	O
newNode	O
"	O
into	O
a	O
circular	O
linked	B-Data_Structure
list	I-Data_Structure
after	O
a	O
given	O
node	B-Data_Structure
"	O
node	B-Data_Structure
"	O
.	O
</s>
<s>
If	O
"	O
node	B-Data_Structure
"	O
is	O
null	O
,	O
it	O
assumes	O
that	O
the	O
list	B-General_Concept
is	O
empty	O
.	O
</s>
<s>
Suppose	O
that	O
"	O
L	O
"	O
is	O
a	O
variable	O
pointing	O
to	O
the	O
last	O
node	B-Data_Structure
of	O
a	O
circular	O
linked	B-Data_Structure
list	I-Data_Structure
(	O
or	O
null	O
if	O
the	O
list	B-General_Concept
is	O
empty	O
)	O
.	O
</s>
<s>
This	O
function	O
inserts	O
a	O
value	O
"	O
newVal	O
"	O
before	O
a	O
given	O
node	B-Data_Structure
"	O
node	B-Data_Structure
"	O
in	O
O(1 )	O
time	O
.	O
</s>
<s>
We	O
create	O
a	O
new	O
node	B-Data_Structure
between	O
"	O
node	B-Data_Structure
"	O
and	O
the	O
next	O
node	B-Data_Structure
,	O
and	O
then	O
put	O
the	O
value	O
of	O
"	O
node	B-Data_Structure
"	O
into	O
that	O
new	O
node	B-Data_Structure
,	O
and	O
put	O
"	O
newVal	O
"	O
in	O
"	O
node	B-Data_Structure
"	O
.	O
</s>
<s>
Thus	O
,	O
a	O
singly	O
linked	O
circularly	O
linked	B-Data_Structure
list	I-Data_Structure
with	O
only	O
a	O
firstNode	O
variable	O
can	O
both	O
insert	O
to	O
the	O
front	O
and	O
back	O
in	O
O(1 )	O
time	O
.	O
</s>
<s>
This	O
function	O
removes	O
a	O
non-null	O
node	B-Data_Structure
from	O
a	O
list	B-General_Concept
of	O
size	O
greater	O
than	O
1	O
in	O
O(1 )	O
time	O
.	O
</s>
<s>
It	O
copies	O
data	B-General_Concept
from	O
the	O
next	O
node	B-Data_Structure
into	O
the	O
node	B-Data_Structure
,	O
and	O
then	O
sets	O
the	O
node	B-Data_Structure
's	O
next	O
pointer	O
to	O
skip	O
over	O
the	O
next	O
node	B-Data_Structure
.	O
</s>
<s>
Languages	O
that	O
do	O
not	O
support	O
any	O
type	O
of	O
reference	O
can	O
still	O
create	O
links	O
by	O
replacing	O
pointers	O
with	O
array	B-Data_Structure
indices	O
.	O
</s>
<s>
The	O
approach	O
is	O
to	O
keep	O
an	O
array	B-Data_Structure
of	O
records	O
,	O
where	O
each	O
record	O
has	O
integer	O
fields	O
indicating	O
the	O
index	B-Data_Structure
of	O
the	O
next	O
(	O
and	O
possibly	O
previous	O
)	O
node	B-Data_Structure
in	O
the	O
array	B-Data_Structure
.	O
</s>
<s>
Not	O
all	O
nodes	O
in	O
the	O
array	B-Data_Structure
need	O
be	O
used	O
.	O
</s>
<s>
If	O
records	O
are	O
also	O
not	O
supported	O
,	O
parallel	B-Data_Structure
arrays	I-Data_Structure
can	O
often	O
be	O
used	O
instead	O
.	O
</s>
<s>
As	O
an	O
example	O
,	O
consider	O
the	O
following	O
linked	B-Data_Structure
list	I-Data_Structure
record	O
that	O
uses	O
arrays	B-Data_Structure
instead	O
of	O
pointers	O
:	O
</s>
<s>
integer	O
next	O
;	O
//	O
index	B-Data_Structure
of	O
next	O
entry	O
in	O
array	B-Data_Structure
integer	O
prev	O
;	O
//	O
previous	O
entry	O
(	O
if	O
double-linked	O
)	O
string	O
name	O
;	O
</s>
<s>
A	O
linked	B-Data_Structure
list	I-Data_Structure
can	O
be	O
built	O
by	O
creating	O
an	O
array	B-Data_Structure
of	O
these	O
structures	O
,	O
and	O
an	O
integer	O
variable	O
to	O
store	O
the	O
index	B-Data_Structure
of	O
the	O
first	O
element	O
.	O
</s>
<s>
Links	O
between	O
elements	O
are	O
formed	O
by	O
placing	O
the	O
array	B-Data_Structure
index	B-Data_Structure
of	O
the	O
next	O
(	O
or	O
previous	O
)	O
cell	O
into	O
the	O
Next	O
or	O
Prev	O
field	O
within	O
a	O
given	O
element	O
.	O
</s>
<s>
In	O
the	O
above	O
example	O
,	O
ListHead	O
would	O
be	O
set	O
to	O
2	O
,	O
the	O
location	O
of	O
the	O
first	O
entry	O
in	O
the	O
list	B-General_Concept
.	O
</s>
<s>
Notice	O
that	O
entry	O
3	O
and	O
5	O
through	O
7	O
are	O
not	O
part	O
of	O
the	O
list	B-General_Concept
.	O
</s>
<s>
These	O
cells	O
are	O
available	O
for	O
any	O
additions	O
to	O
the	O
list	B-General_Concept
.	O
</s>
<s>
By	O
creating	O
a	O
ListFree	O
integer	O
variable	O
,	O
a	O
free	B-General_Concept
list	I-General_Concept
could	O
be	O
created	O
to	O
keep	O
track	O
of	O
what	O
cells	O
are	O
available	O
.	O
</s>
<s>
If	O
all	O
entries	O
are	O
in	O
use	O
,	O
the	O
size	O
of	O
the	O
array	B-Data_Structure
would	O
have	O
to	O
be	O
increased	O
or	O
some	O
elements	O
would	O
have	O
to	O
be	O
deleted	O
before	O
new	O
entries	O
could	O
be	O
stored	O
in	O
the	O
list	B-General_Concept
.	O
</s>
<s>
The	O
following	O
code	O
would	O
traverse	O
the	O
list	B-General_Concept
and	O
display	O
names	O
and	O
account	O
balance	O
:	O
</s>
<s>
The	O
linked	B-Data_Structure
list	I-Data_Structure
is	O
relocatable	O
,	O
meaning	O
it	O
can	O
be	O
moved	O
about	O
in	O
memory	O
at	O
will	O
,	O
and	O
it	O
can	O
also	O
be	O
quickly	O
and	O
directly	O
serialized	B-Application
for	O
storage	O
on	O
disk	O
or	O
transfer	O
over	O
a	O
network	O
.	O
</s>
<s>
Especially	O
for	O
a	O
small	O
list	B-General_Concept
,	O
array	B-Data_Structure
indexes	O
can	O
occupy	O
significantly	O
less	O
space	O
than	O
a	O
full	O
pointer	O
on	O
many	O
architectures	O
.	O
</s>
<s>
Locality	B-General_Concept
of	I-General_Concept
reference	I-General_Concept
can	O
be	O
improved	O
by	O
keeping	O
the	O
nodes	O
together	O
in	O
memory	O
and	O
by	O
periodically	O
rearranging	O
them	O
,	O
although	O
this	O
can	O
also	O
be	O
done	O
in	O
a	O
general	O
store	O
.	O
</s>
<s>
Naïve	O
dynamic	B-General_Concept
memory	I-General_Concept
allocators	I-General_Concept
can	O
produce	O
an	O
excessive	O
amount	O
of	O
overhead	O
storage	O
for	O
each	O
node	B-Data_Structure
allocated	O
;	O
almost	O
no	O
allocation	O
overhead	O
is	O
incurred	O
per	O
node	B-Data_Structure
in	O
this	O
approach	O
.	O
</s>
<s>
Seizing	O
an	O
entry	O
from	O
a	O
pre-allocated	O
array	B-Data_Structure
is	O
faster	O
than	O
using	O
dynamic	B-General_Concept
memory	I-General_Concept
allocation	I-General_Concept
for	O
each	O
node	B-Data_Structure
,	O
since	O
dynamic	B-General_Concept
memory	I-General_Concept
allocation	I-General_Concept
typically	O
requires	O
a	O
search	O
for	O
a	O
free	O
memory	O
block	O
of	O
the	O
desired	O
size	O
.	O
</s>
<s>
Growing	O
a	O
large	O
array	B-Data_Structure
when	O
it	O
is	O
full	O
may	O
be	O
difficult	O
or	O
impossible	O
,	O
whereas	O
finding	O
space	O
for	O
a	O
new	O
linked	B-Data_Structure
list	I-Data_Structure
node	B-Data_Structure
in	O
a	O
large	O
,	O
general	O
memory	B-General_Concept
pool	I-General_Concept
may	O
be	O
easier	O
.	O
</s>
<s>
Adding	O
elements	O
to	O
a	O
dynamic	B-Data_Structure
array	I-Data_Structure
will	O
occasionally	O
(	O
when	O
it	O
is	O
full	O
)	O
unexpectedly	O
take	O
linear	O
(O(n )	O
)	O
instead	O
of	O
constant	O
time	O
(	O
although	O
it	O
's	O
still	O
an	O
amortized	B-General_Concept
constant	O
)	O
.	O
</s>
<s>
Using	O
a	O
general	O
memory	B-General_Concept
pool	I-General_Concept
leaves	O
more	O
memory	O
for	O
other	O
data	B-General_Concept
if	O
the	O
list	B-General_Concept
is	O
smaller	O
than	O
expected	O
or	O
if	O
many	O
nodes	O
are	O
freed	O
.	O
</s>
<s>
For	O
these	O
reasons	O
,	O
this	O
approach	O
is	O
mainly	O
used	O
for	O
languages	O
that	O
do	O
not	O
support	O
dynamic	B-General_Concept
memory	I-General_Concept
allocation	I-General_Concept
.	O
</s>
<s>
These	O
disadvantages	O
are	O
also	O
mitigated	O
if	O
the	O
maximum	O
size	O
of	O
the	O
list	B-General_Concept
is	O
known	O
at	O
the	O
time	O
the	O
array	B-Data_Structure
is	O
created	O
.	O
</s>
<s>
Many	O
programming	O
languages	O
such	O
as	O
Lisp	B-Language
and	O
Scheme	B-Language
have	O
singly	O
linked	B-Data_Structure
lists	I-Data_Structure
built	O
in	O
.	O
</s>
<s>
In	O
many	O
functional	B-Language
languages	I-Language
,	O
these	O
lists	O
are	O
constructed	O
from	O
nodes	O
,	O
each	O
called	O
a	O
cons	B-Protocol
or	O
cons	B-Protocol
cell	O
.	O
</s>
<s>
The	O
cons	B-Protocol
has	O
two	O
fields	O
:	O
the	O
car	B-Language
,	O
a	O
reference	O
to	O
the	O
data	B-General_Concept
for	O
that	O
node	B-Data_Structure
,	O
and	O
the	O
cdr	B-Language
,	O
a	O
reference	O
to	O
the	O
next	O
node	B-Data_Structure
.	O
</s>
<s>
Although	O
cons	B-Protocol
cells	O
can	O
be	O
used	O
to	O
build	O
other	O
data	B-General_Concept
structures	I-General_Concept
,	O
this	O
is	O
their	O
primary	O
purpose	O
.	O
</s>
<s>
In	O
languages	O
that	O
support	O
abstract	O
data	B-General_Concept
types	O
or	O
templates	O
,	O
linked	B-Data_Structure
list	I-Data_Structure
ADTs	O
or	O
templates	O
are	O
available	O
for	O
building	O
linked	B-Data_Structure
lists	I-Data_Structure
.	O
</s>
<s>
In	O
other	O
languages	O
,	O
linked	B-Data_Structure
lists	I-Data_Structure
are	O
typically	O
built	O
using	O
references	O
together	O
with	O
records	O
.	O
</s>
<s>
When	O
constructing	O
a	O
linked	B-Data_Structure
list	I-Data_Structure
,	O
one	O
is	O
faced	O
with	O
the	O
choice	O
of	O
whether	O
to	O
store	O
the	O
data	B-General_Concept
of	O
the	O
list	B-General_Concept
directly	O
in	O
the	O
linked	B-Data_Structure
list	I-Data_Structure
nodes	O
,	O
called	O
internal	O
storage	O
,	O
or	O
merely	O
to	O
store	O
a	O
reference	O
to	O
the	O
data	B-General_Concept
,	O
called	O
external	O
storage	O
.	O
</s>
<s>
Internal	O
storage	O
has	O
the	O
advantage	O
of	O
making	O
access	O
to	O
the	O
data	B-General_Concept
more	O
efficient	O
,	O
requiring	O
less	O
storage	O
overall	O
,	O
having	O
better	O
locality	B-General_Concept
of	I-General_Concept
reference	I-General_Concept
,	O
and	O
simplifying	O
memory	B-General_Concept
management	I-General_Concept
for	O
the	O
list	B-General_Concept
(	O
its	O
data	B-General_Concept
is	O
allocated	O
and	O
deallocated	O
at	O
the	O
same	O
time	O
as	O
the	O
list	B-General_Concept
nodes	O
)	O
.	O
</s>
<s>
External	O
storage	O
,	O
on	O
the	O
other	O
hand	O
,	O
has	O
the	O
advantage	O
of	O
being	O
more	O
generic	O
,	O
in	O
that	O
the	O
same	O
data	B-General_Concept
structure	I-General_Concept
and	O
machine	O
code	O
can	O
be	O
used	O
for	O
a	O
linked	B-Data_Structure
list	I-Data_Structure
no	O
matter	O
what	O
the	O
size	O
of	O
the	O
data	B-General_Concept
is	O
.	O
</s>
<s>
It	O
also	O
makes	O
it	O
easy	O
to	O
place	O
the	O
same	O
data	B-General_Concept
in	O
multiple	O
linked	B-Data_Structure
lists	I-Data_Structure
.	O
</s>
<s>
Although	O
with	O
internal	O
storage	O
the	O
same	O
data	B-General_Concept
can	O
be	O
placed	O
in	O
multiple	O
lists	O
by	O
including	O
multiple	O
next	O
references	O
in	O
the	O
node	B-Data_Structure
data	B-General_Concept
structure	I-General_Concept
,	O
it	O
would	O
then	O
be	O
necessary	O
to	O
create	O
separate	O
routines	O
to	O
add	O
or	O
delete	O
cells	O
based	O
on	O
each	O
field	O
.	O
</s>
<s>
It	O
is	O
possible	O
to	O
create	O
additional	O
linked	B-Data_Structure
lists	I-Data_Structure
of	O
elements	O
that	O
use	O
internal	O
storage	O
by	O
using	O
external	O
storage	O
,	O
and	O
having	O
the	O
cells	O
of	O
the	O
additional	O
linked	B-Data_Structure
lists	I-Data_Structure
store	O
references	O
to	O
the	O
nodes	O
of	O
the	O
linked	B-Data_Structure
list	I-Data_Structure
containing	O
the	O
data	B-General_Concept
.	O
</s>
<s>
In	O
general	O
,	O
if	O
a	O
set	O
of	O
data	B-General_Concept
structures	I-General_Concept
needs	O
to	O
be	O
included	O
in	O
linked	B-Data_Structure
lists	I-Data_Structure
,	O
external	O
storage	O
is	O
the	O
best	O
approach	O
.	O
</s>
<s>
If	O
a	O
set	O
of	O
data	B-General_Concept
structures	I-General_Concept
need	O
to	O
be	O
included	O
in	O
only	O
one	O
linked	B-Data_Structure
list	I-Data_Structure
,	O
then	O
internal	O
storage	O
is	O
slightly	O
better	O
,	O
unless	O
a	O
generic	O
linked	B-Data_Structure
list	I-Data_Structure
package	O
using	O
external	O
storage	O
is	O
available	O
.	O
</s>
<s>
Likewise	O
,	O
if	O
different	O
sets	O
of	O
data	B-General_Concept
that	O
can	O
be	O
stored	O
in	O
the	O
same	O
data	B-General_Concept
structure	I-General_Concept
are	O
to	O
be	O
included	O
in	O
a	O
single	O
linked	B-Data_Structure
list	I-Data_Structure
,	O
then	O
internal	O
storage	O
would	O
be	O
fine	O
.	O
</s>
<s>
Another	O
approach	O
that	O
can	O
be	O
used	O
with	O
some	O
languages	O
involves	O
having	O
different	O
data	B-General_Concept
structures	I-General_Concept
,	O
but	O
all	O
have	O
the	O
initial	O
fields	O
,	O
including	O
the	O
next	O
(	O
and	O
prev	O
if	O
double	O
linked	B-Data_Structure
list	I-Data_Structure
)	O
references	O
in	O
the	O
same	O
location	O
.	O
</s>
<s>
After	O
defining	O
separate	O
structures	O
for	O
each	O
type	O
of	O
data	B-General_Concept
,	O
a	O
generic	O
structure	O
can	O
be	O
defined	O
that	O
contains	O
the	O
minimum	O
amount	O
of	O
data	B-General_Concept
shared	O
by	O
all	O
the	O
other	O
structures	O
and	O
contained	O
at	O
the	O
top	O
(	O
beginning	O
)	O
of	O
the	O
structures	O
.	O
</s>
<s>
Then	O
generic	O
routines	O
can	O
be	O
created	O
that	O
use	O
the	O
minimal	O
structure	O
to	O
perform	O
linked	B-Data_Structure
list	I-Data_Structure
type	O
operations	O
,	O
but	O
separate	O
routines	O
can	O
then	O
handle	O
the	O
specific	O
data	B-General_Concept
.	O
</s>
<s>
The	O
generic	O
routines	O
are	O
used	O
to	O
add	O
new	O
messages	O
to	O
a	O
queue	B-Application
when	O
they	O
are	O
received	O
,	O
and	O
remove	O
them	O
from	O
the	O
queue	B-Application
in	O
order	O
to	O
process	O
the	O
message	O
.	O
</s>
<s>
Suppose	O
you	O
wanted	O
to	O
create	O
a	O
linked	B-Data_Structure
list	I-Data_Structure
of	O
families	O
and	O
their	O
members	O
.	O
</s>
<s>
To	O
print	O
a	O
complete	O
list	B-General_Concept
of	O
families	O
and	O
their	O
members	O
using	O
internal	O
storage	O
,	O
we	O
could	O
write	O
:	O
</s>
<s>
record	O
node	B-Data_Structure
{	O
//	O
generic	O
link	O
structure	O
node	B-Data_Structure
next	O
;	O
</s>
<s>
To	O
print	O
a	O
complete	O
list	B-General_Concept
of	O
families	O
and	O
their	O
members	O
using	O
external	O
storage	O
,	O
we	O
could	O
write	O
:	O
</s>
<s>
Notice	O
that	O
when	O
using	O
external	O
storage	O
,	O
an	O
extra	O
step	O
is	O
needed	O
to	O
extract	O
the	O
record	O
from	O
the	O
node	B-Data_Structure
and	O
cast	O
it	O
into	O
the	O
proper	O
data	B-General_Concept
type	O
.	O
</s>
<s>
This	O
is	O
because	O
both	O
the	O
list	B-General_Concept
of	O
families	O
and	O
the	O
list	B-General_Concept
of	O
members	O
within	O
the	O
family	O
are	O
stored	O
in	O
two	O
linked	B-Data_Structure
lists	I-Data_Structure
using	O
the	O
same	O
data	B-General_Concept
structure	I-General_Concept
(	O
node	B-Data_Structure
)	O
,	O
and	O
this	O
language	O
does	O
not	O
have	O
parametric	O
types	O
.	O
</s>
<s>
If	O
,	O
however	O
,	O
a	O
member	O
needed	O
to	O
be	O
included	O
in	O
an	O
arbitrary	O
number	O
of	O
families	O
,	O
with	O
the	O
specific	O
number	O
known	O
only	O
at	O
run	B-Library
time	I-Library
,	O
external	O
storage	O
would	O
be	O
necessary	O
.	O
</s>
<s>
Finding	O
a	O
specific	O
element	O
in	O
a	O
linked	B-Data_Structure
list	I-Data_Structure
,	O
even	O
if	O
it	O
is	O
sorted	O
,	O
normally	O
requires	O
O(n )	O
time	O
(	O
linear	B-Algorithm
search	I-Algorithm
)	O
.	O
</s>
<s>
This	O
is	O
one	O
of	O
the	O
primary	O
disadvantages	O
of	O
linked	B-Data_Structure
lists	I-Data_Structure
over	O
other	O
data	B-General_Concept
structures	I-General_Concept
.	O
</s>
<s>
In	O
an	O
unordered	O
list	B-General_Concept
,	O
one	O
simple	O
heuristic	O
for	O
decreasing	O
average	O
search	O
time	O
is	O
the	O
move-to-front	O
heuristic''	O
,	O
which	O
simply	O
moves	O
an	O
element	O
to	O
the	O
beginning	O
of	O
the	O
list	B-General_Concept
once	O
it	O
is	O
found	O
.	O
</s>
<s>
This	O
scheme	B-Language
,	O
handy	O
for	O
creating	O
simple	O
caches	O
,	O
ensures	O
that	O
the	O
most	O
recently	O
used	O
items	O
are	O
also	O
the	O
quickest	O
to	O
find	O
again	O
.	O
</s>
<s>
Another	O
common	O
approach	O
is	O
to	O
"	O
index	B-Data_Structure
"	O
a	O
linked	B-Data_Structure
list	I-Data_Structure
using	O
a	O
more	O
efficient	O
external	O
data	B-General_Concept
structure	I-General_Concept
.	O
</s>
<s>
For	O
example	O
,	O
one	O
can	O
build	O
a	O
red	O
–	O
black	O
tree	O
or	O
hash	B-Algorithm
table	I-Algorithm
whose	O
elements	O
are	O
references	O
to	O
the	O
linked	B-Data_Structure
list	I-Data_Structure
nodes	O
.	O
</s>
<s>
Multiple	O
such	O
indexes	O
can	O
be	O
built	O
on	O
a	O
single	O
list	B-General_Concept
.	O
</s>
<s>
The	O
disadvantage	O
is	O
that	O
these	O
indexes	O
may	O
need	O
to	O
be	O
updated	O
each	O
time	O
a	O
node	B-Data_Structure
is	O
added	O
or	O
removed	O
(	O
or	O
at	O
least	O
,	O
before	O
that	O
index	B-Data_Structure
is	O
used	O
again	O
)	O
.	O
</s>
<s>
A	O
random-access	B-General_Concept
list	B-General_Concept
is	O
a	O
list	B-General_Concept
with	O
support	O
for	O
fast	O
random	B-General_Concept
access	I-General_Concept
to	O
read	O
or	O
modify	O
any	O
element	O
in	O
the	O
list	B-General_Concept
.	O
</s>
<s>
One	O
possible	O
implementation	O
is	O
a	O
skew	O
binary	O
random-access	B-General_Concept
list	B-General_Concept
using	O
the	O
skew	B-Application
binary	I-Application
number	I-Application
system	I-Application
,	O
which	O
involves	O
a	O
list	B-General_Concept
of	O
trees	O
with	O
special	O
properties	O
;	O
this	O
allows	O
worst-case	O
constant	O
time	O
head/cons	O
operations	O
,	O
and	O
worst-case	O
logarithmic	O
time	O
random	B-General_Concept
access	I-General_Concept
to	O
an	O
element	O
by	O
index	B-Data_Structure
.	O
</s>
<s>
Random-access	B-General_Concept
lists	O
can	O
be	O
implemented	O
as	O
persistent	B-Application
data	I-Application
structures	I-Application
.	O
</s>
<s>
Random-access	B-General_Concept
lists	O
can	O
be	O
viewed	O
as	O
immutable	O
linked	B-Data_Structure
lists	I-Data_Structure
in	O
that	O
they	O
likewise	O
support	O
the	O
same	O
O(1 )	O
head	O
and	O
tail	O
operations	O
.	O
</s>
<s>
A	O
simple	O
extension	O
to	O
random-access	B-General_Concept
lists	O
is	O
the	O
min-list	O
,	O
which	O
provides	O
an	O
additional	O
operation	O
that	O
yields	O
the	O
minimum	O
element	O
in	O
the	O
entire	O
list	B-General_Concept
in	O
constant	O
time	O
(	O
without	O
mutation	O
complexities	O
)	O
.	O
</s>
<s>
Both	O
stacks	B-Application
and	O
queues	B-Application
are	O
often	O
implemented	O
using	O
linked	B-Data_Structure
lists	I-Data_Structure
,	O
and	O
simply	O
restrict	O
the	O
type	O
of	O
operations	O
which	O
are	O
supported	O
.	O
</s>
<s>
The	O
skip	O
list	B-General_Concept
is	O
a	O
linked	B-Data_Structure
list	I-Data_Structure
augmented	O
with	O
layers	O
of	O
pointers	O
for	O
quickly	O
jumping	O
over	O
large	O
numbers	O
of	O
elements	O
,	O
and	O
then	O
descending	O
to	O
the	O
next	O
layer	O
.	O
</s>
<s>
This	O
process	O
continues	O
down	O
to	O
the	O
bottom	O
layer	O
,	O
which	O
is	O
the	O
actual	O
list	B-General_Concept
.	O
</s>
<s>
A	O
binary	O
tree	O
can	O
be	O
seen	O
as	O
a	O
type	O
of	O
linked	B-Data_Structure
list	I-Data_Structure
where	O
the	O
elements	O
are	O
themselves	O
linked	B-Data_Structure
lists	I-Data_Structure
of	O
the	O
same	O
nature	O
.	O
</s>
<s>
The	O
result	O
is	O
that	O
each	O
node	B-Data_Structure
may	O
include	O
a	O
reference	O
to	O
the	O
first	O
node	B-Data_Structure
of	O
one	O
or	O
two	O
other	O
linked	B-Data_Structure
lists	I-Data_Structure
,	O
which	O
,	O
together	O
with	O
their	O
contents	O
,	O
form	O
the	O
subtrees	O
below	O
that	O
node	B-Data_Structure
.	O
</s>
<s>
An	O
unrolled	B-Data_Structure
linked	I-Data_Structure
list	I-Data_Structure
is	O
a	O
linked	B-Data_Structure
list	I-Data_Structure
in	O
which	O
each	O
node	B-Data_Structure
contains	O
an	O
array	B-Data_Structure
of	O
data	B-General_Concept
values	O
.	O
</s>
<s>
This	O
leads	O
to	O
improved	O
cache	B-General_Concept
performance	O
,	O
since	O
more	O
list	B-General_Concept
elements	O
are	O
contiguous	O
in	O
memory	O
,	O
and	O
reduced	O
memory	O
overhead	O
,	O
because	O
less	O
metadata	O
needs	O
to	O
be	O
stored	O
for	O
each	O
element	O
of	O
the	O
list	B-General_Concept
.	O
</s>
<s>
A	O
hash	B-Algorithm
table	I-Algorithm
may	O
use	O
linked	B-Data_Structure
lists	I-Data_Structure
to	O
store	O
the	O
chains	O
of	O
items	O
that	O
hash	O
to	O
the	O
same	O
position	O
in	O
the	O
hash	B-Algorithm
table	I-Algorithm
.	O
</s>
<s>
A	O
heap	B-Application
shares	O
some	O
of	O
the	O
ordering	O
properties	O
of	O
a	O
linked	B-Data_Structure
list	I-Data_Structure
,	O
but	O
is	O
almost	O
always	O
implemented	O
using	O
an	O
array	B-Data_Structure
.	O
</s>
<s>
Instead	O
of	O
references	O
from	O
node	B-Data_Structure
to	O
node	B-Data_Structure
,	O
the	O
next	O
and	O
previous	O
data	B-General_Concept
indexes	O
are	O
calculated	O
using	O
the	O
current	O
data	B-General_Concept
's	O
index	B-Data_Structure
.	O
</s>
<s>
A	O
self-organizing	B-Data_Structure
list	I-Data_Structure
rearranges	O
its	O
nodes	O
based	O
on	O
some	O
heuristic	O
which	O
reduces	O
search	O
times	O
for	O
data	B-General_Concept
retrieval	O
by	O
keeping	O
commonly	O
accessed	O
nodes	O
at	O
the	O
head	O
of	O
the	O
list	B-General_Concept
.	O
</s>
