Sorting layers by recency

I have a scene where I am attempting to make 3 sprites layer in the order of which sprite was clicked upon last. For example, sprites A B, and C would be on layers 1 2, and 3 and would change between the top and bottom layers depending on how recent they were clicked. The issue is that I have no idea how to get that to work.