int N; // total rooms
volatile Room rooms[1..N]
int nextDirtyRoomNumber = 1
int nextDirtyRoomNumbers[1..N]
foreach i in [1..N]:
nextDirtyRoomNumbers[i] = i + 1
while true:
sleep 1 minute
nextDirtyRoomNumber = checkRooms(nextDirtyRoomNumber)
if nextDirtyRoomNumber == N
break
i = nextDirtyRoomNumber
dirty_room_number = []
do
dirty_room_number.append(i)
i = nextDirtyRoomNumbers[i]
while i
send dirty_room_number
send 'all clean'
function checkRoomsReturnNextDirtyRoomNumber(startNumber):
if startNumber == N:
return N
nextRoomToCheck = nextDirtyRoomNumbers[startNumber]
if rooms[startNumber].dirty:
nextDirtyRoomNumbers[startNumber] = checkRoomsReturnNextDirtyRoomNumber(nextRoomToCheck)
return startNumber
return checkRoomsReturnNextDirtyRoomNumber[nextRoomToCheck)
Dirty rooms
所有跟帖:
•
哈哈,以為是罵人呢。
-貧論元-
♂
(0 bytes)
()
05/11/2009 postreply
06:10:33