Hmm if a a bunch of aliens were surrounding Earth and were going blow up the planet killing everyone unless I was killed, yup I'd be willing to sacrifice myself. However, if it was my friend they wanted to kill, or even some guy I don't know, I would feel like it was wrong. Of course, if the planet exploded, they would die, anyway, but it would still feel wrong, especially since, well, what if the aliens were bluffing? Did anyone bother trying to ask the aliens why they wanted this guy killed or try to reason with them?
As for the train example, would flip the switch. Because it's kinda hard to stop a train if it's close enough unless you're Superman, and untying or cutting the ropes holding one person to the track seems a lot more doable than five,