Java Reference
In-Depth Information
9
59
42
59
42
9
32
39
44
13
32
39
44
13
22
29
14
33
30
17
22
29
14
33
30
17
(a) After moving 9 to the root
(b) After swapping 9 with 59
59
59
42
44
42
44
32
39
9
13
32
39
30
13
22
29
14
33
30
17
22
29
14
33
9
17
(c) After swapping 9 with 44
(d) After swapping 9 with 30
F IGURE 23.14
Rebuild the heap after the root 62 is removed.
Figure 23.15 shows the process of rebuilding a heap after the root, 59, is removed from
Figure 23.14d. Move the last node, 17, to the root, as shown in Figure 23.15a. Swap 17 with
44, as shown in Figure 23.15b, and then swap 17 with 30, as shown in Figure 23.15c.
17
44
42
44
42
17
32
39
30
13
32
39
30
13
22
29
14
33
9
22
29
14
33
9
(a) After moving 17 to the root
(b) After swapping 17 with 44
44
42
30
32
39
17
13
22
29
14
33
9
(c) After swapping 17 with 30
F IGURE 23.15
Rebuild the heap after the root, 59, is removed.
23.6.4 The Heap Class
Now you are ready to design and implement the Heap class. The class diagram is shown in
Figure 23.16. Its implementation is given in Listing 23.9.
 
 
Search WWH ::




Custom Search