CS计算机代考程序代写 data structure ER AI COPE-04 Data Structures.indd

COPE-04 Data Structures.indd

24
5

D
at

a
S

tr
u

ct
u

re
s

©
2

0
2
1
U

w
e

R
.
Z

im
m

er
, T

h
e

A
u
st

ra
li
an

N
at

io
n
al

U
n
iv

er
si

ty

p
ag

e
2
4
5
o

f
4
8
7
(
ch

ap
te

r
4
:
“D

at
a

St
ru

ct
u
re

s”
u

p
t
o
p

ag
e

2
5
3
)

R
ep

la
ci

n
g

m
u
lt

ip
li
ca

ti
o
n
w

it
h
s

h
if

te
d
i
n
d
ex

r
eg

is
te

r

;

r
0

b
a
s
e

a
d
d
r
e
s
s

f
o
r

a
r
r
a
y

a

;

r
1

f
r
o
m

a
r
r
a
y

i
n
d
e
x

;

r
2

t
o

a
r
r
a
y

i
n
d
e
x

m
o
v

r
3
,

#
0

;

s
u
m

:
=

0

f
o
r
_
s
u
m
:

c
m
p

r
1
,

r
2

;

i

>

t
o

b
g
t

e
n
d
_
f
o
r
_
s
u
m

l
d
r

r
4
,

[
r
0
,

r
1
,

l
s
l

#
2
]

;

a

[
i
]

:
=

[
b
a
s
e

+

e
l
e
m
e
n
t
_
o
f
f
s
e
t
]

a
d
d

r
3
,

r
4

;

s
u
m

:
=

s
u
m

+

a

[
i
]

a
d
d

r
1
,

#
1

;

i

:
=

i

+

1

b

f
o
r
_
s
u
m

e
n
d
_
f
o
r
_
s
u
m
:

m
o
v

r
0
,

r
3

;

r
0

s
u
m

o
v
e
r

a
l
l

a

[
f
r
o
m

.
.

t
o
]

1 7 1

24
1

D
at

a
S

tr
u

ct
u

re
s

©
2

0
2
1
U

w
e

R
.
Z

im
m

er
, T

h
e

A
u
st

ra
li
an

N
at

io
n
al

U
n
iv

er
si

ty

p
ag

e
2
4
1
o

f
4
8
7
(
ch

ap
te

r
4
:
“D

at
a

St
ru

ct
u
re

s”
u

p
t
o
p

ag
e

2
5
3
)

C
al

cu
la

te

x
i

/
i
n
t

s
u
m

(
u
n
s
i
g
n
e
d

i
n
t

u
i
n
t
s

[
]
,

u
n
s
i
g
n
e
d

i
n
t

f
r
o
m
,

u
n
s
i
g
n
e
d

i
n
t

t
o
)

{

i
n
t

i
;

i
n
t

a
c
c

=

0
;

f
o
r

(
i

=

f
r
o
m
;

i

< = t o ; i + + ) { a c c + = u i n t s [ i ] ; } r e t u r n a c c ; } t y p e N a t u r a l s i s a r r a y ( I n t e g e r r a n g e < >
)

o
f

N
a
t
u
r
a
l
;

f
u
n
c
t
i
o
n

S
u
m

(
N
u
m
b
e
r
s

:

N
a
t
u
r
a
l
s
)

r
e
t
u
r
n

N
a
t
u
r
a
l

i
s

A
c
c

:

N
a
t
u
r
a
l

:
=

0
;

b
e
g
i
n

f
o
r

n

o
f

N
u
m
b
e
r
s

l
o
o
p

A
c
c

:
=

A
c
c

+

n
;

e
n
d

l
o
o
p
;

r
e
t
u
r
n

A
c
c
;

e
n
d

S
u
m
;

g
)

{
)

{

u
n
s
i
g
n
e
d

i
n
t

u
i
n
t
s

[
1
0
0
]
;

u
n
s
i
g
n
e
d

i
n
t

s
;

i
n
t

i
;

f
o
r

(
i

=

0
;

i

< = 9 9 ; i + + ) { u i n t s [ i ] = r a n d ( ) ; } s = s u m ( u i n t s , 0 , 9 9 ) ; N u m b e r s : c o n s t a n t N a t u r a l s ( 1 . . 1 0 0 ) : = ( o t h e r s = >

R
a
n
d
o
m

(
N
u
m
b
e
r
s
_
G
e
n
e
r
a
t
o
r
)
)
;

S
u
m
_
o
f
_
N
u
m
b
e
r
s

:

c
o
n
s
t
a
n
t

N
a
t
u
r
a
l

:
=

S
u
m

(
N
u
m
b
e
r
s
)
;

23
7

D
at

a
S

tr
u

ct
u

re
s

©
2

0
2
1
U

w
e

R
.
Z

im
m

er
, T

h
e

A
u
st

ra
li
an

N
at

io
n
al

U
n
iv

er
si

ty

p
ag

e
2
3
7
o

f
4
8
7
(
ch

ap
te

r
4
:
“D

at
a

St
ru

ct
u
re

s”
u

p
t
o
p

ag
e

2
5
3
)

A
rr

ay
a

d
d
re

ss
in

g
vi

a
in

d
ex

r
eg

is
te

r

e
0
_
b
0

0
3

4
7

e
0
_
b
1

e
0
_
b
2

e
0
_
b
3

e
1
_
b
0

e
1
_
b
1

e
1
_
b
2

e
1
_
b
3

e
2
_
b
0

e
2
_
b
1

e
2
_
b
2

e
2
_
b
3

e
3
_
b
0

e
3
_
b
1

e
3
_
b
2

e
3
_
b
3

R
b


B

as
e

ad
d

re
ss

R
i


In

d
ex

{
sh

if
te

d
}

+

R
d


D

es
ti

n
at

io
n

}

l
d
r
< c >
< q >

< R d >
,

[
< R b >
,

< R i >

{
,

l
s
l

#
< s h i f t >
}
]

23
3

4
D

at
a

St
ru

ct
u

re
s

U
w

e
R

.
Z

im
m

er

T
h
e

A
u
st

ra
li
an

N
at

io
n
al

U
n
iv

er
si

ty

C
o

m
p

u
te

r
O

rg
an

is
at

io
n

&
P

ro
g

ra
m

E
xe

cu
ti

o
n

2
02

1

24
6

D
at

a
S

tr
u

ct
u

re
s

©
2

0
2
1
U

w
e

R
.
Z

im
m

er
, T

h
e

A
u
st

ra
li
an

N
at

io
n
al

U
n
iv

er
si

ty

p
ag

e
2
4
6
o

f
4
8
7
(
ch

ap
te

r
4
:
“D

at
a

St
ru

ct
u
re

s”
u

p
t
o
p

ag
e

2
5
3
)

R
ep

la
ci

n
g

in
d
ic

es
w

it
h
o

ff
se

ts

;

r
0

b
a
s
e

a
d
d
r
e
s
s

f
o
r

a
r
r
a
y

a

;

r
1

f
r
o
m

a
r
r
a
y

i
n
d
e
x

;

r
2

t
o

a
r
r
a
y

i
n
d
e
x

l
s
l

r
1
,

r
1
,

#
2

;

t
r
a
n
s
l
a
t
e

f
r
o
m

i
n
d
e
x

t
o

o
f
f
s
e
t

l
s
l

r
2
,

r
2
,

#
2

;

t
r
a
n
s
l
a
t
e

t
o

i
n
d
e
x

t
o

o
f
f
s
e
t

m
o
v

r
3
,

#
0

;

s
u
m

:
=

0

f
o
r
_
s
u
m
:

c
m
p

r
1
,

r
2

;

i

>

t
o

b
g
t

e
n
d
_
f
o
r
_
s
u
m

l
d
r

r
4
,

[
r
0
,

r
1
]

;

a

[
i
]

:
=

[
b
a
s
e

+

o
f
f
s
e
t
]

a
d
d

r
3
,

r
4

;

s
u
m

:
=

s
u
m

+

a

[
i
]

a
d
d

r
1
,

#
4

;

o
f
f
s
e
t

:
=

o
f
f
s
e
t

+

4

b

f
o
r
_
s
u
m

e
n
d
_
f
o
r
_
s
u
m
:

m
o
v

r
0
,

r
3

;

r
0

s
u
m

o
v
e
r

a
l
l

a

[
f
r
o
m

.
.

t
o
]

3 7 1

24
2

D
at

a
S

tr
u

ct
u

re
s

©
2

0
2
1
U

w
e

R
.
Z

im
m

er
, T

h
e

A
u
st

ra
li
an

N
at

io
n
al

U
n
iv

er
si

ty

p
ag

e
2
4
2
o

f
4
8
7
(
ch

ap
te

r
4
:
“D

at
a

St
ru

ct
u
re

s”
u

p
t
o
p

ag
e

2
5
3
)

C
al

cu
la

te

x
i

/
i
n
t

s
u
m

(
u
n
s
i
g
n
e
d

i
n
t

u
i
n
t
s

[
]
,

u
n
s
i
g
n
e
d

i
n
t

f
r
o
m
,

u
n
s
i
g
n
e
d

i
n
t

t
o
)

{

i
n
t

i
;

i
n
t

a
c
c

=

0
;

f
o
r

(
i

=

f
r
o
m
;

i

< = t o ; i + + ) { a c c + = u i n t s [ i ] ; } r e t u r n a c c ; } t y p e N a t u r a l s i s a r r a y ( I n t e g e r r a n g e < >
)

o
f

N
a
t
u
r
a
l
;

f
u
n
c
t
i
o
n

S
u
m

(
N
u
m
b
e
r
s

:

N
a
t
u
r
a
l
s
)

r
e
t
u
r
n

N
a
t
u
r
a
l

i
s

A
c
c

:

N
a
t
u
r
a
l

:
=

0
;

b
e
g
i
n

f
o
r

n

o
f

N
u
m
b
e
r
s

l
o
o
p

A
c
c

:
=

A
c
c

+

n
;

e
n
d

l
o
o
p
;

r
e
t
u
r
n

A
c
c
;

e
n
d

S
u
m
;

g
)

{
)

{
)

{
)

{

u
n
s
i
g
n
e
d

i
n
t

u
i
n
t
s

[
1
0
0
]
;

u
n
s
i
g
n
e
d

i
n
t

s
;

i
n
t

i
;

f
o
r

(
i

=

0
;

i

< = 9 9 ; i + + ) { u i n t s [ i ] = r a n d ( ) ; } s = s u m ( u i n t s , 0 , 9 9 ) ; N u m b e r s : c o n s t a n t N a t u r a l s ( 1 . . 1 0 0 ) : = ( o t h e r s = >

R
a
n
d
o
m

(
N
u
m
b
e
r
s
_
G
e
n
e
r
a
t
o
r
)
)
;

S
u
m
_
o
f
_
N
u
m
b
e
r
s

:

c
o
n
s
t
a
n
t

N
a
t
u
r
a
l

:
=

S
u
m

(
N
u
m
b
e
r
s
)
;

} s

;

B
e

st
o

f
lu

ck
w

it
h

t
h

e
a

rr
ay

b
o

u
n

d
s!

23
8

D
at

a
S

tr
u

ct
u

re
s

©
2

0
2
1
U

w
e

R
.
Z

im
m

er
, T

h
e

A
u
st

ra
li
an

N
at

io
n
al

U
n
iv

er
si

ty

p
ag

e
2
3
8
o

f
4
8
7
(
ch

ap
te

r
4
:
“D

at
a

St
ru

ct
u
re

s”
u

p
t
o
p

ag
e

2
5
3
)

A
rr

ay
a

d
d
re

ss
in

g
vi

a
in

d
ex

r
eg

is
te

r

e
0
_
b
0

0
3

4
7

e
0
_
b
1

e
0
_
b
2

e
0
_
b
3

e
1
_
b
0

e
1
_
b
1

e
1
_
b
2

e
1
_
b
3

e
2
_
b
0

e
2
_
b
1

e
2
_
b
2

e
2
_
b
3

e
3
_
b
0

e
3
_
b
1

e
3
_
b
2

e
3
_
b
3

R
b


B

as
e

ad
d

re
ss

R
i


In

d
ex

{
sh

if
te

d
}

+

R
d


D

es
ti

n
at

io
n

}

l
d
r
< c >
< q >

< R d >
,

[
< R b >
,

< R i >

{
,

l
s
l

#
< s h i f t >
}
]

S
h

if
t

w
o

rk
s

if
e

s
2

n
=

2
b
22
b
22

_
b
2
b
3
b
3

_
b
3
b
0

_ _
ee
2
ee
2
ee
2
_

e
2
e
2
e
2
_

e
3

e
2
_ _

e
3
e
3
e
3

C
an

b
e

h
an

d
y

if
R
i
i

s
ac

tu
al

ly
a

n
i

n
d

e
x.

e
3
_
b
2

e
3
_
b
2

e
3

b
3

3
b

e
3

b
3

e
3

b
3

b
0
b
0

e
3
_
b
0

e
3

b
1

e
3

b
1

e
3

b
1

33
e
333
e
3

000 11
e
3
_
b
1

e
3

b
2

e
3

b
2

e
3

b
2

O
th

e
rw

is
e

R
i
w

il
l

b
e

a
b

yt
e

o
ff

se
t.

23
4

D
at

a
S

tr
u

ct
u

re
s

©
2

0
2
1
U

w
e

R
.
Z

im
m

er
, T

h
e

A
u
st

ra
li
an

N
at

io
n
al

U
n
iv

er
si

ty

p
ag

e
2
3
4
o

f
4
8
7
(
ch

ap
te

r
4
:
“D

at
a

St
ru

ct
u
re

s”
u

p
t
o
p

ag
e

2
5
3
)

R
ef

er
en

ce
s

fo
r

th
is

c
h
ap

te
r

[P
at

te
rs

o
n

17
]

D
av

id
A

. P
at

te
rs

o
n

&
J

o
h

n
L

. H
e

n
n

e
ss

y
C

o
m

p
u

te
r

O
rg

an
iz

at
io

n
a

n
d

D
e

si
g

n

T
h

e
H

ar
d

w
ar

e
/S

o
ft

w
ar

e
I

n
te

rf
ac

e
C

h
ap

te
r

2
“I

n
st

ru
ct

io
n

s:
L

an
g

u
ag

e
o

f
th

e
C

o
m

p
u

te
r”

,
C

h
ap

te
r

5
“L

ar
g

e
a

n
d

F
as

t:
E

xp
lo

it
in

g
M

e
m

o
ry

H
ie

ra
rc

h
y”

A
R

M
e

d
it

io
n

, M
o

rg
an

K
au

fm
an

n
2

01
7

24
7

D
at

a
S

tr
u

ct
u

re
s

©
2

0
2
1
U

w
e

R
.
Z

im
m

er
, T

h
e

A
u
st

ra
li
an

N
at

io
n
al

U
n
iv

er
si

ty

p
ag

e
2
4
7
o

f
4
8
7
(
ch

ap
te

r
4
:
“D

at
a

St
ru

ct
u
re

s”
u

p
t
o
p

ag
e

2
5
3
)

A
ss

u
m

in
g

n
o
n
-e

m
p
ty

a
rr

ay
s

;

r
0

b
a
s
e

a
d
d
r
e
s
s

f
o
r

a
r
r
a
y

a

;

r
1

f
r
o
m

a
r
r
a
y

i
n
d
e
x

;

r
2

t
o

a
r
r
a
y

i
n
d
e
x

>
=

f
r
o
m

i
n
d
e
x

l
s
l

r
1
,

r
1
,

#
2

;

t
r
a
n
s
l
a
t
e

f
r
o
m

i
n
d
e
x

t
o

o
f
f
s
e
t

l
s
l

r
2
,

r
2
,

#
2

;

t
r
a
n
s
l
a
t
e

t
o

i
n
d
e
x

t
o

o
f
f
s
e
t

m
o
v

r
3
,

#
0

;

s
u
m

:
=

0

f
o
r
_
s
u
m
:

l
d
r

r
4
,

[
r
0
,

r
1
]

;

a

[
i
]

:
=

[
b
a
s
e

+

o
f
f
s
e
t
]

a
d
d

r
3
,

r
4

;

s
u
m

:
=

s
u
m

+

a

[
i
]

a
d
d

r
1
,

#
4

;

o
f
f
s
e
t

:
=

o
f
f
s
e
t

+

4

c
m
p

r
1
,

r
2

;

i

< = t o b l e f o r _ s u m e n d _ f o r _ s u m : m o v r 0 , r 3 ; r 0 s u m o v e r a l l a [ f r o m . . t o ] 3 6 1 24 3 D at a S tr u ct u re s © 2 0 2 1 U w e R . Z im m er , T h e A u st ra li an N at io n al U n iv er si ty p ag e 2 4 3 o f 4 8 7 ( ch ap te r 4 : “D at a St ru ct u re s” u p t o p ag e 2 5 3 ) A rb it ra ry a rr ay i n d ex in g ; r 0 b a s e a d d r e s s f o r a r r a y a ; r 1 f r o m a r r a y i n d e x ; r 2 t o a r r a y i n d e x m o v r 3 , # 0 ; s u m : = 0 m o v r 4 , # 4 ; e l e m e n t s i z e i s 4 b y t e s m o v r 5 , # - 1 ; f i r s t _ e l e m e n t _ o f f s e t f o r _ s u m : c m p r 1 , r 2 ; i >

t
o

b
g
t

e
n
d
_
f
o
r
_
s
u
m

m
l
a

r
6
,

r
1
,

r
4
,

r
5

;

e
l
e
m
e
n
t
_
o
f
f
s
e
t

:
=

(
i

*

4
)

f
i
r
s
t
_
e
l
e
m
e
n
t
_
o
f
f
s
e
t

l
d
r

r
7
,

[
r
0
,

r
6
]

;

a

[
i
]

:
=

[
b
a
s
e

+

e
l
e
m
e
n
t
_
o
f
f
s
e
t
]

a
d
d

r
3
,

r
7

;

s
u
m

:
=

s
u
m

+

a

[
i
]

a
d
d

r
1
,

#
1

;

i

:
=

i

+

1

b

f
o
r
_
s
u
m

e
n
d
_
f
o
r
_
s
u
m
:

m
o
v

r
0
,

r
3

;

r
0

s
u
m

o
v
e
r

a
l
l

a

[
f
r
o
m

.
.

t
o
]

3 9 1

23
9

D
at

a
S

tr
u

ct
u

re
s

©
2

0
2
1
U

w
e

R
.
Z

im
m

er
, T

h
e

A
u
st

ra
li
an

N
at

io
n
al

U
n
iv

er
si

ty

p
ag

e
2
3
9
o

f
4
8
7
(
ch

ap
te

r
4
:
“D

at
a

St
ru

ct
u
re

s”
u

p
t
o
p

ag
e

2
5
3
)

A
rr

ay
a

d
d
re

ss
in

g
vi

a
el

em
en

t
p
o
in

te
r

e
0
_
b
0

0
3

4
7

e
0
_
b
1

e
0
_
b
2

e
0
_
b
3

e
1
_
b
0

e
1
_
b
1

e
1
_
b
2

e
1
_
b
3

e
2
_
b
0

e
2
_
b
1

e
2
_
b
2

e
2
_
b
3

e
3
_
b
0

e
3
_
b
1

e
3
_
b
2

e
3
_
b
3

R
d


D

es
ti

n
at

io
n

}
R

p

A
rr

ay
p

o
in

te
r

El
em

en
t

o
ff

se
t

W
ri

te
-b

ac
k

+

l
d
r
< c >
< q >

< R d >
,

[
< R p >
]
,

#
+
/

< o f f s e t >

23
5

D
at

a
S

tr
u

ct
u

re
s

©
2

0
2
1
U

w
e

R
.
Z

im
m

er
, T

h
e

A
u
st

ra
li
an

N
at

io
n
al

U
n
iv

er
si

ty

p
ag

e
2
3
5
o

f
4
8
7
(
ch

ap
te

r
4
:
“D

at
a

St
ru

ct
u
re

s”
u

p
t
o
p

ag
e

2
5
3
)

A
rr

ay
l
ay

o
u
t

e
0
_
b
0

0
3

4
7

e
0
_
b
1

e
0
_
b
2

e
1
_
b
0

e
1
_
b
2

e
2
_
b
0

e
2
_
b
1

e
2
_
b
2

e
2
_
b
3

e
3
_
b
0

e
3
_
b
1

e
3
_
b
2

e
3
_
b
3

}
x

+
4

x x
+

8

x
+

1
2

A
rr

ay
e

le
m

en
t

Lo
w

er
a

rr
ay

b
o

u
n

d

U
p

p
er

a
rr

ay
b

o
u

n
d

x
+

1
5

El
e

m
e

n
ts

o
f

e
q

u
al

s
iz

e

se
q

u
e

n
ti

al
ly

i
n

m
e

m
o

ry

24
8

D
at

a
S

tr
u

ct
u

re
s

©
2

0
2
1
U

w
e

R
.
Z

im
m

er
, T

h
e

A
u
st

ra
li
an

N
at

io
n
al

U
n
iv

er
si

ty

p
ag

e
2
4
8
o

f
4

8
7
(
ch

ap
te

r
4
:
“D

at
a

St
ru

ct
u
re

s”
u

p
t
o
p

ag
e

2
5
3
)

R
ep

la
ci

n
g

o
ff

se
ts

w
it

h
a

d
d
re

ss
es

;

r
0

b
a
s
e

a
d
d
r
e
s
s

f
o
r

a
r
r
a
y

a

;

r
1

f
r
o
m

a
r
r
a
y

i
n
d
e
x

;

r
2

t
o

a
r
r
a
y

i
n
d
e
x

>
=

f
r
o
m

i
n
d
e
x

l
s
l

r
1
,

r
1
,

#
2

;

t
r
a
n
s
l
a
t
e

f
r
o
m

i
n
d
e
x

t
o

o
f
f
s
e
t

l
s
l

r
2
,

r
2
,

#
2

;

t
r
a
n
s
l
a
t
e

t
o

i
n
d
e
x

t
o

o
f
f
s
e
t

a
d
d

r
1
,

r
0

;

t
r
a
n
s
l
a
t
e

f
r
o
m

i
n
d
e
x

t
o

a
d
d
r
e
s
s


>

i
_
a
d
d
r

a
d
d

r
2
,

r
0

;

t
r
a
n
s
l
a
t
e

t
o

i
n
d
e
x

t
o

a
d
d
r
e
s
s


>

t
o
_
a
d
d
r

m
o
v

r
0
,

#
0

;

s
u
m

:
=

0

f
o
r
_
s
u
m
:

l
d
r

r
3
,

[
r
1
]
,

#
4

;

a

[
i
]

:
=

[
i
_
a
d
d
r
]
;

i
_
a
d
d
r

+
=

4

a
d
d

r
0
,

r
3

;

s
u
m

:
=

s
u
m

+

a

[
i
]

c
m
p

r
1
,

r
2

;

i
_
a
d
d
r

< = t o _ a d d r b l e f o r _ s u m e n d _ f o r _ s u m : ; r 0 s u m o v e r a l l a [ f r o m . . t o ] 5 5 24 4 D at a S tr u ct u re s © 2 0 2 1 U w e R . Z im m er , T h e A u st ra li an N at io n al U n iv er si ty p ag e 2 4 4 o f 4 8 7 ( ch ap te r 4 : “D at a St ru ct u re s” u p t o p ag e 2 5 3 ) Z er o -b as ed a rr ay i n d ex in g ; r 0 b a s e a d d r e s s f o r a r r a y a ; r 1 f r o m a r r a y i n d e x ; r 2 t o a r r a y i n d e x m o v r 3 , # 0 ; s u m : = 0 m o v r 4 , # 4 ; e l e m e n t s i z e i s 4 b y t e s f o r _ s u m : c m p r 1 , r 2 ; i >

t
o

b
g
t

e
n
d
_
f
o
r
_
s
u
m

m
u
l

r
5
,

r
1
,

r
4

;

e
l
e
m
e
n
t
_
o
f
f
s
e
t

:
=

(
i

*

4
)

l
d
r

r
6
,

[
r
0
,

r
5
]

;

a

[
i
]

:
=

[
b
a
s
e

+

e
l
e
m
e
n
t
_
o
f
f
s
e
t
]

a
d
d

r
3
,

r
6

;

s
u
m

:
=

s
u
m

+

a

[
i
]

a
d
d

r
1
,

#
1

;

i

:
=

i

+

1

b

f
o
r
_
s
u
m

e
n
d
_
f
o
r
_
s
u
m
:

m
o
v

r
0
,

r
3

;

r
0

s
u
m

o
v
e
r

a
l
l

a

[
f
r
o
m

.
.

t
o
]

2 8 1

24
0

D
at

a
S

tr
u

ct
u

re
s

©
2

0
2
1
U

w
e

R
.
Z

im
m

er
, T

h
e

A
u
st

ra
li
an

N
at

io
n
al

U
n
iv

er
si

ty

p
ag

e
2
4
0
o

f
4

8
7
(
ch

ap
te

r
4
:
“D

at
a

St
ru

ct
u
re

s”
u

p
t
o
p

ag
e

2
5
3
)

A
rr

ay
a

d
d
re

ss
in

g
vi

a
el

em
en

t
p
o
in

te
r

e
0
_
b
0

0
3

4
7

e
0
_
b
1

e
0
_
b
2

e
0
_
b
3

e
1
_
b
0

e
1
_
b
1

e
1
_
b
2

e
1
_
b
3

e
2
_
b
0

e
2
_
b
1

e
2
_
b
2

e
2
_
b
3

e
3
_
b
0

e
3
_
b
1

e
3
_
b
2

e
3
_
b
3

R
d


D

es
ti

n
at

io
n

}
R

p

A
rr

ay
p

o
in

te
r

El
em

en
t

o
ff

se
t

W
ri

te
-b

ac
k

+

l
d
r
< c >
< q >

< R d >
,

[
< R p >
]
,

#
+
/

< o f f s e t >

2222 33
e
3

b
2

e
3

b
2

ee
3
_
b
2

e
3
_
b
3

3
_
b

e
3

b
3

e
3

b
3

Ef
fi

ci
e

n
t

if
a

rr
ay

h
as

t
o

b
e

w
o

rk
e

d
s

e
q

u
e

n
ti

al
ly

23
6

D
at

a
S

tr
u

ct
u

re
s

©
2

0
2
1
U

w
e

R
.
Z

im
m

er
, T

h
e

A
u
st

ra
li
an

N
at

io
n
al

U
n
iv

er
si

ty

p
ag

e
2
3
6
o

f
4

8
7
(
ch

ap
te

r
4
:
“D

at
a

St
ru

ct
u
re

s”
u

p
t
o
p

ag
e

2
5
3
)

A
rr

ay
a

d
d
re

ss
in

g

e
0
_
b
0

0
3

4
7

e
0
_
b
1

e
0
_
b
2

e
0
_
b
3

e
1
_
b
0

e
1
_
b
1

e
1
_
b
2

e
1
_
b
3

e
2
_
b
0

e
2
_
b
1

e
2
_
b
2

e
2
_
b
3

e
3
_
b
0

e
3
_
b
1

e
3
_
b
2

e
3
_
b
3

}
x

+
1

·e
s

x
+

0
·e

s

x
+

2
·e

s

x
+

3
·e

s

El
em

en
t

si
ze

(
es

)
4

b
yt

es

Lo
w

er
a

rr
ay

b
o

u
n

d

U
p

p
er

a
rr

ay
b

o
u

n
d

x
+

4
·e

s

1

x
+

i
·e

s

M
ay

b
e

b
e

g
o

o
d

t
o

h

av
e

e
s

2
n

=
?

W
h

at
h

ap
p

e
n

s
if

a
rr

ay

b
o

u
n

d
s

ar
e

v
io

la
te

d
?

l

A
n

d
w

h
o

i
s

ch
e

ck
in

g
t

h
at

?

C
an

a
rr

ay
s

al
w

ay
s

b
e

st

o
re

d

p
ac

k
e

d
”?

25
3

D
at

a
S

tr
u

ct
u

re
s

©
2

0
2
1
U

w
e

R
.
Z

im
m

er
, T

h
e

A
u
st

ra
li
an

N
at

io
n
al

U
n
iv

er
si

ty

p
ag

e
2
5
3
o

f
4
8
7
(
ch

ap
te

r
4
:
“D

at
a

St
ru

ct
u
re

s”
u

p
t
o
p

ag
e

2
5
3
)

D
at

a
S

tr
u

ct
u

re
s


A

rr
ay

s


S

tr
u

ct
u

re


A

li
g

n
m

e
n

t


A

d
d

re
ss

in
g


It

e
ra

to
rs


C

o
p

y
p

ro
ce

d
u

re
s

Su
m

m
ar

y

24
9

D
at

a
S

tr
u

ct
u

re
s

©
2

0
2
1
U

w
e

R
.
Z

im
m

er
, T

h
e

A
u
st

ra
li
an

N
at

io
n
al

U
n
iv

er
si

ty

p
ag

e
2
4
9
o

f
4
8
7
(
ch

ap
te

r
4
:
“D

at
a

St
ru

ct
u
re

s”
u

p
t
o
p

ag
e

2
5
3
)

A
rr

ay
S

li
ce

s
n
u
m
b
e
r
s

=

[
0
,

1
,

2
,

3
,

4
,

5
]

n
u
m
b
e
r
s
S
l
i
c
e

=

n
u
m
b
e
r
s

[
1
:
3
]

#

n
u
m
b
e
r
s
S
l
i
c
e

e
q
u
a
l
s

[
1
,

2
,

3
]

n
u
m
b
e
r
s

:
=

[
]
i
n
t

{
0
,

1
,

2
,

3
,

4
,

5
}

n
u
m
b
e
r
s
S
l
i
c
e

:
=

n
u
m
b
e
r
s

[
1
:
3
]

t
y
p
e

N
a
t
u
r
a
l
s

i
s

a
r
r
a
y

(
I
n
t
e
g
e
r

r
a
n
g
e

< >
)

o
f

N
a
t
u
r
a
l
;

N
u
m
b
e
r
s

:

c
o
n
s
t
a
n
t

N
a
t
u
r
a
l
s

(

5
0

.
.

5
0
)

:
=

(
o
t
h
e
r
s

=
>

R
a
n
d
o
m

(
G
e
n
e
r
a
t
o
r
)
)
;

N
u
m
b
e
r
s
_
S
l
i
c
e
_
1

:

c
o
n
s
t
a
n
t

N
a
t
u
r
a
l
s

:
=

N
u
m
b
e
r
s

(

1
0

.
.

1
0
)
;

N
u
m
b
e
r
s
_
S
l
i
c
e
_
2

:

c
o
n
s
t
a
n
t

N
a
t
u
r
a
l
s

(

1

.
.

1
0
)

:
=

N
u
m
b
e
r
s

(

1
1

.
.

2
0
)
;

N
u
m
b
e
r
s
_
S
l
i
c
e
_
3

:

N
a
t
u
r
a
l
s

:
=

N
u
m
b
e
r
s

(

2
0

.
.

5
0
)
;

b
e
g
i
n

f
o
r

n

o
f

N
u
m
b
e
r
s
_
S
l
i
c
e
_
3

l
o
o
p

n

:
=

n

+

1
;

e
n
d

l
o
o
p
;

e
n
d
;

25
0

D
at

a
S

tr
u

ct
u

re
s

©
2

0
2
1
U

w
e

R
.
Z

im
m

er
, T

h
e

A
u
st

ra
li
an

N
at

io
n
al

U
n
iv

er
si

ty

p
ag

e
2
5
0
o

f
4
8
7
(
ch

ap
te

r
4
:
“D

at
a

St
ru

ct
u
re

s”
u

p
t
o
p

ag
e

2
5
3
)

A
rr

ay
S

li
ce

s
n
u
m
b
e
r
s

=

[
0
,

1
,

2
,

3
,

4
,

5
]

n
u
m
b
e
r
s
S
l
i
c
e

=

n
u
m
b
e
r
s

[
1
:
3
]

#

n
u
m
b
e
r
s
S
l
i
c
e

e
q
u
a
l
s

[
1
,

2
,

3
]

n
u
m
b
e
r
s

:
=

[
]
i
n
t

{
0
,

1
,

2
,

3
,

4
,

5
}

n
u
m
b
e
r
s
S
l
i
c
e

:
=

n
u
m
b
e
r
s

[
1
:
3
]

t
y
p
e

N
a
t
u
r
a
l
s

i
s

a
r
r
a
y

(
I
n
t
e
g
e
r

r
a
n
g
e

< >
)

o
f

N
a
t
u
r
a
l
;

N
u
m
b
e
r
s

:

c
o
n
s
t
a
n
t

N
a
t
u
r
a
l
s

(

5
0

.
.

5
0
)

:
=

(
o
t
h
e
r
s

=
>

R
a
n
d
o
m

(
G
e
n
e
r
a
t
o
r
)
)
;

N
u
m
b
e
r
s
_
S
l
i
c
e
_
1

:

c
o
n
s
t
a
n
t

N
a
t
u
r
a
l
s

:
=

N
u
m
b
e
r
s

(

1
0

.
.

1
0
)
;

N
u
m
b
e
r
s
_
S
l
i
c
e
_
2

:

c
o
n
s
t
a
n
t

N
a
t
u
r
a
l
s

(

1

.
.

1
0
)

:
=

N
u
m
b
e
r
s

(

1
1

.
.

2
0
)
;

N
u
m
b
e
r
s
_
S
l
i
c
e
_
3

:

N
a
t
u
r
a
l
s

:
=

N
u
m
b
e
r
s

(

2
0

.
.

5
0
)
;

b
e
g
i
n

f
o
r

n

o
f

N
u
m
b
e
r
s
_
S
l
i
c
e
_
3

l
o
o
p

n

:
=

n

+

1
;

e
n
d

l
o
o
p
;

e
n
d
;

A
re

t
h

o
se

c
o

p
y

o
r

re
fe

re
n

ce
a

ff
ai

rs
?

25
1

D
at

a
S

tr
u

ct
u

re
s

©
2

0
2
1
U

w
e

R
.
Z

im
m

er
, T

h
e

A
u
st

ra
li
an

N
at

io
n
al

U
n
iv

er
si

ty

p
ag

e
2
5
1
o

f
4
8
7
(
ch

ap
te

r
4
:
“D

at
a

St
ru

ct
u
re

s”
u

p
t
o
p

ag
e

2
5
3
)

C
o
py

a
rr

ay
s

li
ce

;

r
0

b
a
s
e

a
d
d
r
e
s
s

f
o
r

a
r
r
a
y

a

;

r
1

f
r
o
m

a
r
r
a
y

i
n
d
e
x

;

r
2

t
o

a
r
r
a
y

i
n
d
e
x

>
=

f
r
o
m

i
n
d
e
x

;

r
3

b
a
s
e

a
d
d
r
e
s
s

f
o
r

a
r
r
a
y

b

l
s
l

r
1
,

r
1
,

#
2

;

t
r
a
n
s
l
a
t
e

f
r
o
m

i
n
d
e
x

t
o

o
f
f
s
e
t

l
s
l

r
2
,

r
2
,

#
2

;

t
r
a
n
s
l
a
t
e

t
o

i
n
d
e
x

t
o

o
f
f
s
e
t

a
d
d

r
1
,

r
0

;

t
r
a
n
s
l
a
t
e

f
r
o
m

i
n
d
e
x

t
o

a
d
d
r
e
s
s


>

i
_
a
d
d
r

a
d
d

r
2
,

r
0

;

t
r
a
n
s
l
a
t
e

t
o

i
n
d
e
x

t
o

a
d
d
r
e
s
s


>

t
o
_
a
d
d
r

f
o
r
_
c
o
p
y
:

l
d
r

r
4
,

[
r
1
]
,

#
4

;

a

[
i
]

:
=

[
i
_
a
d
d
r
]
;

i
_
a
d
d
r

+
=

4

s
t
r

r
4
,

[
r
3
]
,

#
4

;

[
j
_
a
d
d
r
]

:
=

a

[
i
]

;

j
_
a
d
d
r

+
=

4

c
m
p

r
1
,

r
2

;

i
_
a
d
d
r

< = t o _ a d d r b l e f o r _ c o p y e n d _ f o r _ c o p y : ; b [ ] : = a [ f r o m . . t o ] 4 6 25 2 D at a S tr u ct u re s © 2 0 2 1 U w e R . Z im m er , T h e A u st ra li an N at io n al U n iv er si ty p ag e 2 5 2 o f 4 8 7 ( ch ap te r 4 : “D at a St ru ct u re s” u p t o p ag e 2 5 3 ) C o py a rr ay s li ce ; r 0 b a s e a d d r e s s f o r a r r a y a ; r 1 f r o m a r r a y i n d e x ; r 2 t o a r r a y i n d e x >
=

f
r
o
m

i
n
d
e
x

;

r
3

b
a
s
e

a
d
d
r
e
s
s

f
o
r

a
r
r
a
y

b

l
s
l

r
1
,

r
1
,

#
2

;

t
r
a
n
s
l
a
t
e

f
r
o
m

i
n
d
e
x

t
o

o
f
f
s
e
t

l
s
l

r
2
,

r
2
,

#
2

;

t
r
a
n
s
l
a
t
e

t
o

i
n
d
e
x

t
o

o
f
f
s
e
t

a
d
d

r
1
,

r
0

;

t
r
a
n
s
l
a
t
e

f
r
o
m

i
n
d
e
x

t
o

a
d
d
r
e
s
s


>

i
_
a
d
d
r

a
d
d

r
2
,

r
0

;

t
r
a
n
s
l
a
t
e

t
o

i
n
d
e
x

t
o

a
d
d
r
e
s
s


>

t
o
_
a
d
d
r

f
o
r
_
c
o
p
y
:

l
d
r

r
4
,

[
r
1
]
,

#
4

;

a

[
i
]

:
=

[
i
_
a
d
d
r
]
;

i
_
a
d
d
r

+
=

4

s
t
r

r
4
,

[
r
3
]
,

#
4

;

[
j
_
a
d
d
r
]

:
=

a

[
i
]

;

j
_
a
d
d
r

+
=

4

c
m
p

r
1
,

r
2

;

i
_
a
d
d
r

< = t o _ a d d r b l e f o r _ c o p y e n d _ f o r _ c o p y : ; b [ ] : = a [ f r o m . . t o ] 4 6 p ag e 2 5 2 o f 4 8 7 ( ch ap te r 4 : “D at a St ru ct u re s” u p t o p 7 p ag e 2 5 2 o f 4 8 7 ( h t 4 “D t St 7 M o vi n g b lo ck s o f m e m o ry c an b e d o n e e ve n /m u ch f as te r w it h s p e ci al h ar d w ar e . D M A c o n tr o ll er s