Partial implementation of join sort