chapter 8 exercise 8-3: reimplement median by iterator