Actually, the surgical mask isn't going to do you much good - you would be better off persuading the coughing passenger to wear it (to reduce the spread of germs).
As for what you can do the next time, the most important steps you could take are: 1) wash your hands frequently during the flight and for a while afterward (hot, soapy water - wash for at least a minute; and b) be careful to avoid touching your eyes, nose and mouth with your hands (unless you just washed your hands 5 seconds ago).
When you get off the flight, dose yourself up on Vitamin C and echinacea, and make sure you get enough sleep for the next few days. If you exercise, avoid heavy workouts for a few days (but no need to stop exercising altogether).