Java Reference
In-Depth Information
sorted list
unsorted list
[0]
[1]
[2]
[3]
[4]
[5]
[6]
[7]
list
10
18
25
30
23
17
45
35
move
FIGURE 14-7 Move list[4] into list[2]
To move list[4] into list[2] , first we copy list[4] into temp , a temporary
memory space (see Figure 14-8).
sorted list
unsorted list
[0]
[1]
[2]
[3]
[4]
[5]
[6]
[7]
list
10
18
25
30
23
17
45
35
temp
23
copy
FIGURE 14-8 Copy list[4] into temp
Next, we copy list[3] into list[4] ,andthen list[2] into list[3] (see Figure 14-9).
sorted list
unsorted list
[0]
[1]
[2]
[3]
[4]
[5]
[6]
[7]
list
10
18
25
30
23
17
45
35
copy
copy
temp
23
FIGURE 14-9 List before copying list[3] into list[4] , and then list[2] into list[3]
After copying list[3] into list[4] and list[2] into list[3] , the list is as shown in
Figure 14-10.
Search WWH ::




Custom Search