How do I implement drag and drop behavior where objects "snap" out of the way of the dragged object?

I have a tower defense game I’m working on. In it, players drag on a GUI button, instantiating a “ghost tower” which when dropped on the grid destroys the “ghost” and instantiates the actual tower. Now the problem I’m trying to solve is when I drag/hover the ghost over an existing tower, I want the tower to snap one grid space down to make room for it. If I remove the ghost from that space, I want that tower to snap back to its original place. If I release the ghost, I want to build a new tower in that square and I want the old tower to remain in it’s new place.

The tricky bit is…I want this behavior to work across multiple towers. For example, If I drag a ghost into a space with an existing tower. I want that tower to snap one space down. Now, if THAT space also has a tower, I want it to snap one space down, and so forth. I then want them all to snap back into place if I remove the ghost, or remain in their new locations if I release it.

I’m having a hard time wrapping my head around this problem. I have a nagging suspicion that recursion is the answer, but so far my hamfisted solutions haven’t worked out. Any help would be appreciated it.

If it helps, at the moment my grid consists of an array of objects created from a “coordinate” class that holds some information. I can access grid members by their coordinates, by their worldspace location, or their index in the array. I’ve also been storing in these objects which towers they are paired with at a given time.

I would greatly appreciate someone helping me to start thinking about this the right way.

Do the towers always move down?