Closest pair algorithm from CSC321