A Novel Sorting Algorithm and its Application to a Gamma-Ray Telescope Asynchronous Data Acquisition System