Concept : Basic Data Structure, Link List Theory, and.... clear mind.
Noticeable Point :
- Some complex and reusable code can be extracted as a inline function.
- Modularize helps a lot.
- Main concept of this solution is not hard. First, we make a structure of each block with these elements :
- box* uplink and box* downlink, these two pointer points to upper and lower block in the pile. If uplink == NULL means it is the top of the pile. If downlink == NULL means it is the lowest block in the pile, or alone, and IT STAND ON THE ORIGINAL PLACE.
- static int BoxID. This indicates where the original place is, and the number of the block. In fact, by the problem saying, if a block.downlink = NULL, it MUST on its original place, as BoxID.
- Constructor and Destructor, which are supposed to control BoxID.
- Define the function respectively. For example, we can draw a blueprint of procedure that "Move Over" does. First, we find that it need a function to clear all boxes above target, so we must make a clearup(). The procedure is simple, clearup() both target and destination, move target to the top of destination. Then, we must make clearup(), how it does? we find that we need a function to get the top box's position, so we must make a box* gettop(). Do this again and again we will get every function ready. In my works, I have made MoveOnto(), MoveOver(), PileOnto(), PileOver(), gettop(), clearup().
- Then assemble these components up. It is not very easy to debug, we must do a hard labor to make sure these works fine. Then, output module seems not complex, do it and debut this patiently... yes you will need lots of patient.
No comments:
Post a Comment