Tuesday, October 24, 2006

Deleting from Arrays

What do we do when we are done with swimming? We have a shower, take the stuff out of the locker, dress up and leave. Let us skip over the showering part and concentrate on the "take the stuff out of the locker" portion, shall we?
If we breakdown the task further, we can see that what we need to do is:
1. Find our locker
2. Remove the contents of the locker and thereby made the locker empty
3. Leave all other lockers as they were, undisturbed.

How do we find our locker? One way is to have remembered the number/location of our locker. Or the key to the locker had the locker number written on it. That way, we just go straight to the locker [ remember, the lockers are numbered sequentially, so finding the nth locker is a fairly easy step].

If we have not remembered the number of the locker, then we need to open each locker and check if it contains our stuff - a laborious and time-consuming activity.

Removing the contents of the locker is fairly easy - we transfer the contents of our locker into our hand, thereby making the locker empty.

Finally, we leave the other lockers as they are, provided, that is what we want to do. Now, supposing we had used the "fastest draw" method that we had seen earlier in Inserting into arrays part 4 to insert? Then, we may want to move the stuff in other lockers back to where they were before we inserted our stuff. To do that, we will have to repeat our activity of moving the empty locker back to where it was, pretty much the same way we moved it to where we wanted it to be. Try out the code for that yourself, if you can.

1 comment:

PVS said...

wat happend to u.. u hav stopped posting..