SLIDE 1 Flooding
- If the spot on the drawing is not empty
– return
- Color the spot using c
- Create a to-do list with spot as its element
- While the to-do list is not empty
– Pop an element from the to-do list and assign it to v – If v’s left is empty, paint it and add to to-do list – If v’s right is empty, paint it and add to to-do list – If v’s above is empty, paint it and add to to-do list – If v’s below is empty, paint it and add to to-do list
SLIDE 2
Example
SLIDE 3
Suppose spot is ( 6, 12 )
spot on drawing is not empty, so no flooding to perform
SLIDE 4
Suppose spot is ( 7, 7 )
spot on drawing is empty, so there is flooding to perform
SLIDE 5
Flood drawing starting at spot ( 7, 7 ) using c
SLIDE 6
Flood drawing starting at spot ( 7, 7 ) using c
spot (7,7) c
SLIDE 7
spot (7,7) c
Flood drawing starting at spot ( 7, 7 ) using c
SLIDE 8
Paint spot
spot (7,7) c
SLIDE 9
Create to-do list
spot (7,7) c to-do list
SLIDE 10 Add spot to to-do list
spot (7,7) c to-do list
SLIDE 11 Loop while to-do list is not empty
spot (7,7) c to-do list
SLIDE 12 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c to-do list
SLIDE 13
Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (7,7) to-do list
SLIDE 14
Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (7,7) to-do list
SLIDE 15 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (7,7) to-do list
SLIDE 16 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (7,7) to-do list
SLIDE 17 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (7,7) to-do list
SLIDE 18 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (7,7) to-do list
SLIDE 19 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (7,7) to-do list
SLIDE 20 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (7,7) to-do list
SLIDE 21 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (7,7) to-do list
SLIDE 22 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (6,7) to-do list
SLIDE 23 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (6,7) to-do list
SLIDE 24 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (6,7) to-do list
SLIDE 25 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (6,7) to-do list
SLIDE 26 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (6,7) to-do list
SLIDE 27 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (6,7) to-do list
SLIDE 28 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (6,7) to-do list
- (8,7)
- (7,6)
- (7,8)
- (6,6)
- (6,8)
SLIDE 29 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (8,7) to-do list
SLIDE 30 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (8,7) to-do list
SLIDE 31 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (8,7) to-do list
SLIDE 32 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (8,7) to-do list
- (7,6)
- (7,8)
- (6,6)
- (6,8)
- (9,7)
SLIDE 33 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (8,7) to-do list
- (7,6)
- (7,8)
- (6,6)
- (6,8)
- (9,7)
SLIDE 34 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (8,7) to-do list
- (7,6)
- (7,8)
- (6,6)
- (6,8)
- (9,7)
- (8,6)
SLIDE 35 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (8,7) to-do list
- (7,6)
- (7,8)
- (6,6)
- (6,8)
- (9,7)
- (8,6)
SLIDE 36 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (8,7) to-do list
- (7,6)
- (7,8)
- (6,6)
- (6,8)
- (9,7)
- (8,6)
- (8,8)
y
SLIDE 37 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (7,6) to-do list
- (7,8)
- (6,6)
- (6,8)
- (9,7)
- (8,6)
- (8,8)
SLIDE 38 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (7,6) to-do list
- (7,8)
- (6,6)
- (6,8)
- (9,7)
- (8,6)
- (8,8)
SLIDE 39 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (7,6) to-do list
- (7,8)
- (6,6)
- (6,8)
- (9,7)
- (8,6)
- (8,8)
SLIDE 40 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (7,6) to-do list
- (7,8)
- (6,6)
- (6,8)
- (9,7)
- (8,6)
- (8,8)
SLIDE 41 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (7,6) to-do list
- (7,8)
- (6,6)
- (6,8)
- (9,7)
- (8,6)
- (8,8)
- (7,5)
SLIDE 42 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (7,6) to-do list
- (7,8)
- (6,6)
- (6,8)
- (9,7)
- (8,6)
- (8,8)
- (7,5)
SLIDE 43 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (7,8) to-do list
- (6,6)
- (6,8)
- (9,7)
- (8,6)
- (8,8)
- (7,5)
SLIDE 44 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (7,8) to-do list
- (6,6)
- (6,8)
- (9,7)
- (8,6)
- (8,8)
- (7,5)
SLIDE 45 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (6,6) to-do list
- (6,8)
- (9,7)
- (8,6)
- (8,8)
- (7,5)
SLIDE 46 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (6,6) to-do list
- (6,8)
- (9,7)
- (8,6)
- (8,8)
- (7,5)
SLIDE 47 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (6,6) to-do list
- (6,8)
- (9,7)
- (8,6)
- (8,8)
- (7,5)
- (6,5)
SLIDE 48 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (6,8) to-do list
- (9,7)
- (8,6)
- (8,8)
- (7,5)
- (6,5)
SLIDE 49 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (6,8) to-do list
- (9,7)
- (8,6)
- (8,8)
- (7,5)
- (6,5)
SLIDE 50 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (6,8) to-do list
- (9,7)
- (8,6)
- (8,8)
- (7,5)
- (6,5)
- (5,8)
- (6,9)
SLIDE 51 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (9,7) to-do list
- (8,6)
- (8,8)
- (7,5)
- (6,5)
- (5,8)
- (6,9)
SLIDE 52 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (9,7) to-do list
- (8,6)
- (8,8)
- (7,5)
- (6,5)
- (5,8)
- (6,9)
- (10,7)
- (9,6)
- (9,8)
SLIDE 53 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (8,6) to-do list
- (8,8)
- (7,5)
- (6,5)
- (5,8)
- (6,9)
- (10,7)
- (9,6)
- (9,8)
SLIDE 54 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (8,6) to-do list
- (8,8)
- (7,5)
- (6,5)
- (5,8)
- (6,9)
- (10,7)
- (9,6)
- (9,8)
- (8,5)
SLIDE 55 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (8,8) to-do list
- (7,5)
- (6,5)
- (5,8)
- (6,9)
- (10,7)
- (9,6)
- (9,8)
- (8,5)
SLIDE 56 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (8,8) to-do list
- (7,5)
- (6,5)
- (5,8)
- (6,9)
- (10,7)
- (9,6)
- (9,8)
- (8,5)
SLIDE 57 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (7,5) to-do list
- (6,5)
- (5,8)
- (6,9)
- (10,7)
- (9,6)
- (9,8)
- (8,5)
SLIDE 58 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (7,5) to-do list
- (6,5)
- (5,8)
- (6,9)
- (10,7)
- (9,6)
- (9,8)
- (8,5)
- (7,4)
SLIDE 59 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (6,5) to-do list
- (5,8)
- (6,9)
- (10,7)
- (9,6)
- (9,8)
- (8,5)
- (7,4)
SLIDE 60 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (6,5) to-do list
- (5,8)
- (6,9)
- (10,7)
- (9,6)
- (9,8)
- (8,5)
- (7,4)
SLIDE 61 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (5,8) to-do list
- (6,9)
- (10,7)
- (9,6)
- (9,8)
- (8,5)
- (7,4)
SLIDE 62 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (5,8) to-do list
- (6,9)
- (10,7)
- (9,6)
- (9,8)
- (8,5)
- (7,4)
- (4,8)
- (5,9)
SLIDE 63 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (6,9) to-do list
- (10,7)
- (9,6)
- (9,8)
- (8,5)
- (7,4)
- (4,8)
- (5,9)
SLIDE 64 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (6,9) to-do list
- (10,7)
- (9,6)
- (9,8)
- (8,5)
- (7,4)
- (4,8)
- (5,9)
- (6,10)
SLIDE 65 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (10,7) to-do list
- (9,6)
- (9,8)
- (8,5)
- (7,4)
- (4,8)
- (5,9)
- (6,10)
SLIDE 66 Loop while to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list spot (7,7) c v (10,7) to-do list
- (9,6)
- (9,8)
- (8,5)
- (7,4)
- (4,8)
- (5,9)
- (6,10)
- (11,7)
- (10,6)
- (10,8)